02-10-2012 06:20 AM
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
Solved! Go to Solution.
02-10-2012 08:19 AM
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!
02-10-2012 09:30 AM
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.
02-10-2012 10:15 AM
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")
02-10-2012 03:24 PM
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?
02-13-2012 05:00 AM
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