I've set up a lot of projects in my project, and if there are 100 of them, I want to write a script to make Moldflow Synergy do the analysis automatically, how do I do that?
Gelöst! Gehe zur Lösung
Gelöst von mason.myers. Gehe zur Lösung
Hello @1292909313 ,
Here is the code for a script that should run all the studies in your project. If you have anything already solved in your project, it might re-solve those studies.
Mason
'@
'@ DESCRIPTION
'@ This command will run all Models in the current directory
'@ It will Delete all old results first then re-run all analyses
'@
'@ SYNTAX
'@ ReRunAllResults
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@@
Option Explicit
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
Dim StudyDoc,Project
Set StudyDoc = Synergy.StudyDoc()
Set Project = Synergy.Project
If Not Project Is nothing Then
Dim lStudy, Modified
lStudy = Project.GetFirstStudyName()
While lStudy <> ""
' Open the Study
Project.OpenItemByName lStudy, "Study"
' Delete All Results if they exist
Dim PlotMgr, Plot
Set PlotMgr = Synergy.PlotManager()
Set Plot = PlotMgr.GetFirstPlot
Modified = false
If Not Plot Is Nothing Then
Set StudyDoc = Synergy.StudyDoc
StudyDoc.DeleteResults(0)
Modified = true
End If
lStudy = Project.GetNextStudyName(lStudy)
Set StudyDoc = Synergy.StudyDoc()
If Modified Then
StudyDoc.Save
End if
StudyDoc.Close
Wend
Else
MsgBox "Please Open a Project",vbCritical,WScript.ScriptName
WScript.Quit(1)
End if
' Re run all the analyses one at a time
lStudy = Project.GetFirstStudyName()
While lStudy <> ""
Project.OpenItemByName lStudy, "Study"
Set StudyDoc = Synergy.StudyDoc
Dim NumberOfAnalysesInSequence
NumberOfAnalysesInSequence = StudyDoc.NumberOfAnalyses
' Run the Analysis
StudyDoc.AnalyzeNow2 False, True, False
' Check That the last analysis in the sequence has completed
Dim Running, Count, Status, Failed
Running = 1
Count = 0
While (Running)
' Wait 5 seconds
Wscript.Sleep(5000)
' Check Analysis status of last run in the Analysis sequence
Status = StudyDoc.AnalysisStatus(NumberOfAnalysesInSequence-1)
If Status = "Completed" Then
Running = 0
End If
If Status = "Failed" Then
Running = 0
End If
Wend
lStudy = Project.GetNextStudyName(lStudy)
StudyDoc.Save
StudyDoc.Close
Wend
MsgBox "Script Complete",,WScript.ScriptName
WScript.Quit(0)
I opened the project and called the .vbs script from the Command Line within Moldflow Synergy. You might be able to run this script from the Command Shell but I have not tried that approach.
Mason
Sie finden nicht, was Sie suchen? Fragen Sie die Community oder teilen Sie Ihr Wissen mit anderen.