I have an issue with the latest MF release regarding scripts.
As an example I have a simple recorded script.
The main problem is to change the name of the plot (in this case to "Plastic Soul")
'%RunPerInstance
'@ DESCRIPTION
'@ Macro recorded by Synergy on 04-Jul-2016 at 14:57:27
SetLocale("en-us")
Dim SynergyGetter, Synergy
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
Set Synergy = SynergyGetter.GetSASynergy
Else
Set Synergy = CreateObject("synergy.Synergy")
End If
Synergy.SetUnits "Metric"
Set PlotManager = Synergy.PlotManager()
Set Plot = PlotManager.CreatePlotByDsID2(1540, 10)
Plot.SetName "Plastic_Soul"
Plot.SetFirstAnimationFrameIndex 1
Plot.SetLastAnimationFrameIndex 96
Plot.SetScaleOption 2
Plot.SetMinValue 80
Plot.SetMaxValue 320
Plot.SetNumberOfContours 2
Plot.SetPlotMethod 4
Set Viewer = Synergy.Viewer()
Viewer.ShowPlot Plot
I tried to record the macro in 2021.2 and also tried to edit it - but with no effort so far.
The API documentation still has these examples and commands listed.
What happen when run this one? It creates a new temperature plot but does not name it!
So the "Plot.SetName" seems not to work.
I have nearly the same script in an Excel-Sheet beyond a button - this now throughs a runtime error 429 at me.
So there seem to be some changes how MF deals with scripts?
Best regards
Harald
Hi Harald,
I have not seen the naming issues in an older script I use, but does look a bit different.
I actually do it on two lines, naming the plot first.
PlotName = "Plastic_Soul"
Plot.SetName PlotName
Could you give it a try?
Might be a workaround, but I think your code should run anyway.
Regards,
Berndt
Hi @bernor_mf Berndt,
much appreciated, but so far no success.
I copied your lines to my freshly recorded script to ensure it will work.
PlotName = "Plastic_Soul"
Plot.SetName PlotName
'%RunPerInstance
'@ DESCRIPTION
'@ Macro recorded by Synergy on 22-Jun-2022 at 08:41:19
SetLocale("en-us")
Dim SynergyGetter, Synergy
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
Set Synergy = SynergyGetter.GetSASynergy
Else
Set Synergy = CreateObject("synergy.Synergy")
End If
Synergy.SetUnits "Metric"
Set PlotManager = Synergy.PlotManager()
Set Plot = PlotManager.CreatePlotByDsID2(1540, 10)
Set Viewer = Synergy.Viewer()
Viewer.ShowPlot Plot
Set Viewer = Synergy.Viewer()
Set Plot = Viewer.GetPlot(40)
PlotName = "Plastic_Soul"
Plot.SetName PlotName
Plot.SetNumberOfAnimationFrames 29
Plot.SetFirstAnimationFrameIndex 31
Plot.SetLastAnimationFrameIndex 89
Plot.SetNumberOfContours 1
Plot.SetPlotMethod 4
Plot.Regenerate
It leaves the plot with the name "Temperature_1" - maybe I need to try GET.PLOT first?
Nevertheless - the question stays current - why do some scripts not work in 2021.2?
Something must be different in the way it is beeing handled.
Thanks anyway Berndt
Harald
Hi Harald,
I copied the script code from post.
Pasted to Notepad.
Saved as "test.vbs", in ANSI-format.
Believe or not, but it ran perfectly fine!
The first time...
But when I run it a second time, it says "Temperature_1"
You find plot by plot ID number. First might be 40, but not next, hence you get "Temperature_1"
Set Plot = Viewer.GetPlot(40)
If you create the plot and find by name it will be renamed:
'%RunPerInstance
'@ DESCRIPTION
'@ Macro recorded by Synergy on 22-Jun-2022 at 08:41:19
SetLocale("en-us")
Dim SynergyGetter, Synergy
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
Set Synergy = SynergyGetter.GetSASynergy
Else
Set Synergy = CreateObject("synergy.Synergy")
End If
Synergy.SetUnits "Metric"
Set PlotManager = Synergy.PlotManager()
Set Plot = PlotManager.CreatePlotByDsID2(1540, 10)
Set Viewer = Synergy.Viewer()
Viewer.ShowPlot Plot
Set Viewer = Synergy.Viewer()
Set Plot = PlotManager.FindPlotByName( "Temperature_1")
'** Set Plot = Viewer.GetPlot(40)
PlotName = "Plastic_Soul"
Plot.SetName PlotName
Plot.SetNumberOfAnimationFrames 29
Plot.SetFirstAnimationFrameIndex 31
Plot.SetLastAnimationFrameIndex 89
Plot.SetNumberOfContours 1
Plot.SetPlotMethod 4
Plot.Regenerate
Good Morning Berndt,
I copied the full script, saved it as *.vbs and ran it - ended up with a temperature_1 plot.
The devil is in the detail somewhere.
Even if this is not what I would call a "programmed" script (just a recorded macro) - it worked for me since 2016 in any Moldflow release - now it doesn't work anymore.
So my conclusion stays - something as changed and I would like to know what exactly it is.
Thanks for your help anyway - a little learning for me was at least the result of this.
Harald
Good Morning to you too Harald,
thank you for the feedback.
I am really puzzled by your issue, as we see different behavior for you and me running the script.
Agree on that something seems to have changed. Would really like to understand what.
Are you on Win English OS as well?
(Shouldn't matter, but anyway...)
Autodesk tech support need to look in to this, I think.
Regards,
Berndt
I also use a script to generate some custom plots.. and from time to time results are not renamed correctly.. I never could reproduce this. sometimes latest plot is renamed after moving the mouse..
did you try without findplotbyname? maybe there is anothe Plot named like this. i renamed it direclty like
Set Plot = PlotManager.CreatePlotByDsID2(6250, 10)
Plot.SetEdgeDisplay 5
Plot.SetPlotMethod 3
Plot.SetDeflectionLCS 0
Plot.SetDeflectionScaleFactor 5
Plot.SetDeflectionScaleDirection 31
Plot.SetName "Warp_all_scaled_5x"
PlotManager.MarkResultForExport "Warp_all_scaled_5x", true
text = "custom plot"
Plot.SetNotes text
Can't find what you're looking for? Ask the community or share your knowledge.