DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to put automatically call a picture (graphic) file into the Report with a script file

Solved!
Go to solution

Hi,

 

Is there a code to automate the report creation process by calling in a picture (.jpg) file? The closest help I can find is in the link below but the instructions here create a 2D graph (which in itself, is very helpful!).

 

https://decibel.ni.com/content/docs/DOC-3994

 

Thanks

0 Kudos
Message 1 of 6
(5,708 Views)
Solution
Accepted by Kevster

After a couple of hours messing around I have found the answer. Example code is:

 

Call GraphObjNew("FreeGraph","Picture")
Call GraphObjOpen("Picture")
       MTAFILENAME ="<File Path>\Picture.bmp"
       MTAPOSX =20
       MTAPOSY =20
       MTAWIDTH =50
Call GraphObjClose("Picture")
Call PicUpdate

 

Hope this helps someone else!

Message 2 of 6
(5,703 Views)

Hey Kevster -

 

Glad you figured out your own solution!

 

Have you heard of the Script Recorder in DIAdem?  If you're looking to do something programmatically with SCRIPT, you can turn on the Script Recorder, perform that action interactively, and then see what function calls the Script Recorder printed out.  

 

For actions in REPORT, one more step is required.  When you are looking to modify something programmatically in REPORT, double-click to open the dialog you want to work with (e.g. double-click on an image in your REPORT to open up the Graphic Options dialog box) and press Ctrl+A.  With Script Recorder turned on, this command will programmatically print out all of the variables necessary to modify the options configured by the dialog you were looking at.  So, for the Graphic Options dialog specifically, you would've gotten the following printout in SCRIPT:

 

'------------------- Graphic --------------------------
Call GraphObjOpen("Metafile2")
  MtaFileName      = "LIBR\Documents\EXAMPLE1.EMF"
  MtaPosX          = 11.5
  MtaPosY          = 84.58
  MtaRelPos        = "r-bot."
  MtaWidth         = 25.79
  MtaHeight        = 26.13
  MtaRatioAdapt    = 1
  MtaBackColor     = ""
  MtaBackRGB       = 0
  MtaEmbedded      = 0
Call GraphObjClose("Metafile2")

...which might have helped you come to an answer faster.

 

Don't forget that it's often easier to create a few templates interactively and load them programmatically (one function call) versus trying to programmatically create a report layout from scratch.

Derrick S.
Product Manager
NI DIAdem
National Instruments
Message 3 of 6
(5,698 Views)

Hi Derrick,

 

Thanks for your response. The Ctrl+A trick I only became aware of this morning and it did help me figure out what I was doing. However, I have found once I have put in the picture file, I get the error message:

 

Invalid variable access (ISMASTERLAYOUT).

Parent object open?

 

if I open a second object in that Report sheep, e.g adding a comment box. Could you tell me why this is? What am I doing wrong?

 

Kevster

 

 

Code example:

 

Call GraphObjNew("FreeGraph","Graph")
Call GraphObjOpen("Graph")
MTAFILENAME =MyFolders(0)&"Picture.bmp"
MTAPOSX =45
MTAPOSY =46
MTAWIDTH =88
Call GraphObjClose("Graph")
Call PicUpdate(0)

 

Call GraphObjNew("Comment","Title")
Call GraphObjOpen("Title")
'------------------- Comment ------------------------
CmtTxt="@@Data.Root.ChannelGroups(""2-02"").Properties(""Question"").Value@@"
CmtTxtFont = "Arial"
CmtTxtSize = 3
CmtTxtColor = "dark blue"
CmtTxtColorRGB = 0
CmtTxtAlignment = "left"
CmtTxtBold = 0
CmtTxtItal = 0
CmtTxtUndl = 0
CmtTxtStrOut = 0
'------------------- Frame and Arrow ----------------
CmtFrameLnColor = ""
CmtFrameLnColRGB = 33554432
CmtFrameLnWidth = "0"
CmtFrameLnType = "solid"
CmtFrameBkColor = ""
CmtFrameBkColRGB = 15204351
CmtFrameBkColRGB2= 15263976
CmtFrameBackFMode= "Vertical"
CmtFrameBackFVariant= "From bottom"
CmtArrowLnColor = "white"
CmtArrowLnColRGB = 33554432
CmtArrowLnWidth = "0.25"
CmtArrowLnType = ""
CmtArrowSymbBeg = "NoArrow"
CmtArrowSymbEnd = "NoArrow"
'------------------- Position -----------------------
CmtFramePT(1) = 1 'X1
CmtFramePT(2) = 80 'Y1
CmtFramePT(3) = 96 'X2
CmtFramePT(4) = 98 'Y2
CmtArrowStartPTX = 0
CmtArrowStartPTY = 0
CmtArrowEndPTX = 0
CmtArrowEndPTY = 0
CmtArrowPTPos = 1
Call GraphObjClose("Title")

0 Kudos
Message 4 of 6
(5,694 Views)

Hey Kevster -

 

I was able to reproduce the behavior with your code snippet (thanks for providing that!), and it looks like this is a bug.  Good news is, it's an easy fix - it seems that the software is having trouble with your use of the name "Graph" to name your imagery.  Try changing this to any alternative word (I used my name as a test) and see if it doesn't clear up the issue.  In the meantime, I'll report this to R&D and get it fixed for a future release of the software.

 

Let us know?

Derrick S.
Product Manager
NI DIAdem
National Instruments
0 Kudos
Message 5 of 6
(5,683 Views)

Derrick, 

 

I can conform that the error does go away when I change the name of the comment box to something else.

 

Thanks for all your help.

 

Kevster

0 Kudos
Message 6 of 6
(5,662 Views)