08-19-2021 07:18 AM
Hello everyone,
I just switched from DIAdem 2015 to DIAdem 2021 and I wanted to execute a script but got an error at the point where I use GraphObjNew:
Call GraphObjNew("FreeGraph","Metafile2")
Call GraphObjOpen("Metafile2")
MtaFileName = "@@T8@@"
MtaRelPos = "r-bot."
MtaHeight = 30.0
MtaRatioAdapt = 0
MtaWidth = 1/MtaRatio*MtaHeight
MtaPosX = 50.0-MtaWidth/2
MtaPosY = 77.97
MtaBackColor = ""
MtaBackRGB = 0
MtaEmbedded = 0
Call GraphObjClose("Metafile2")
The error message says: Variable is undefined. Is there another command that replaced GraphObjNew and GraphObjOpen, or can you recommend another workaround?
Thanks a lot for your help!
Solved! Go to Solution.
08-20-2021 07:00 AM
Hello Z2424,
Hope you are doing well,
Is it possible that the error pops up when you are double-clicking on .VBS file and trying to run from windows?
If yes, try to load the file to the DIAdem Script panel and then run it.
Best Regards
08-21-2021 05:37 PM
Hi Z,
No, I'm afraid DIAdem has obsoleted all the old GraphObj...() commands and variables, and now all the REPORT panel automization must be accomplished with the "Report" object. Is the code you sent in basically all that you need to upgrade, or are you sitting on thousands of lines of code that have "GraphObj..." in them?
Brad Turpin
Principal Technical Support Engineer
NI
08-23-2021 02:10 AM
Hello Brad,
thank you for your answer. Luckily, it's only this bit I sent in my initial request. As you might have seen, I'm trying to include a picture in a report. It should have a height of 30.0 and the width should be according to the original ratio. Is there a way to get the original image ratio (height/width)?
Regards
Z2424
08-23-2021 11:14 AM
Hi Z,
I believe this script does what your GraphObj...() approach was doing. It should at the very least provide a roadmap.
OPTION EXPLICIT
Dim Sheet, Image, MRatio, MHeight, MWidth
T8 = "EXAMPLE4.PNG"
Set Sheet = Report.Sheets(1)
Set Image = Sheet.Objects("Metafile2")
Image.FileName = "@@T8@@"
Image.Embedded = False
Image.BackgroundColor.ColorIndex = eColorIndexNone
Image.UseOriginalRatio = True
MRatio = Image.OriginalRatio
MHeight = 30.0
MWidth = 1/MRatio*MHeight
Image.Position.ByCoordinate.Height = MHeight
Image.Position.ByCoordinate.Width = MWidth
Image.Position.ByCoordinate.X2 = 50.0-MWidth/2
Image.Position.ByCoordinate.Y2 = 77.97
Call Report.Refresh()
Cheers,
Brad Turpin
Principal Technical Support Engineer
NI
08-23-2021 11:18 AM
Hi again Z,
The script I just sent assumes that you have an image object named "Metafile2" on sheet1 of your loaded REPORT layout. You can load this layout I was testing with if my code doesn't mesh perfectly with your layout. It wasn't obvious from your code which sheet you were operating on.
Brad Turpin
Principal Technical Support Engineer
NI
08-24-2021 05:45 AM
Hello Brad,
thanks again for your help. With your support I got my script running with the new DIAdem version and everything is running as intended.
Best regards!