Hello,
I'm a french student. And I have a little problem.
I want to make a VBA Macro who launch Fill/Pack analisys and when the Fill/Pack analysis is finished the Macro launch the Fill/Pack/Warp analysis.
I want to do this, because when I launch Fill/Pack/Warp, I use Premium license during all the analysis time and with this Macro I can use Basic license during Fill/Pack analsis time and Premium License during only Warp analysis time.
I managed to make a macro that change the sequence analysis but this macro can't wait the end of Fill/Pack analysis for change to Fill/Pack/Warp analysis. I just can put one time (like 20sec) to wait but I can't know when the Fill/Pack analysis is finished.
If someone has an answer
thanks
Romain GUY
Solved! Go to Solution.
Solved by nordhb. Go to Solution.
Hi,
you can actually check the status of a job in job manager via macro.
You have to find the job, either by loop through the jobs and find the model or find by name and check status, wait and repeat loop.
When no longer finding job or getting the status in job manager, it is completed, you exit the loop and you can continue and relaunch.
Please, see Help - API Reference, and search JobManager and/or JobMgr
(to the right of question mark, there is a small arrow down to click and select API Reference)
Hope this helps.
Regards,
Berndt
hello,
I have find the API reference and JobMgr. Thanks, I didn't know that help existed.
But, I don't arrived to use the AnalysisStatus. I don't know, what's aIndex and the i-th analysis.
I have post my code here, if you have a response about that.
String AnalysisStatus | ( | long | aIndex | ) |
|
Gets the status of the i-th analysis
Parameters:
| aIndex | index of analysis |
Returns:
Status of the i-th analysis, which can be one of the following.
Private Sub Btndeb_Click() Dim rep As String rep = completed Dim a As String 'launch the Flow analysis Set Synergy = CreateObject("synergy.Synergy") Synergy.SetUnits "Metric" Set Studydoc = Synergy.Studydoc() Studydoc.AnalysisSequence "Flow" Set Studydoc = Synergy.Studydoc() Studydoc.AnalyzeNow False, True 'Take the name of the study Dim StudyName As String Set Studydoc = Synergy.Studydoc() StudyName = Studydoc.StudyName StudyName = Left(StudyName, Len(StudyName) - 4) Studydoc.Close 'Wait the end of the flow analysis Do Set Studydoc = Synergy.Studydoc() a = StudyDoc.AnalsisStatus Loop While a<>rep 'Open the study Set Project = Synergy.Project Project.OpenItemByName StudyName, "Study" 'Launch the Fill/Pack/Warp analysis Set Studydoc = Synergy.Studydoc() Studydoc.AnalysisSequence "Flow|Warp" Set Studydoc = Synergy.Studydoc() Studydoc.AnalyzeNow False, True Studydoc.Close End Sub
Regards,
Romain GUY
Hi,
to check the first analysis sequence is 0, so
a = StudyDoc.AnalysisStatus(0)
(there was a typo in code)
Then set
rep = "Completed"
so string comparison is right.
This should make it run.
Regards,
Berndt
hi,
The code doesn't work. I think we can't use :
Do
Set StudyDoc = Synergy.StudyDoc
a = StudyDoc.AnalysisStatus(0)
Loop While a <> rep
if I close the study with StudyDoc.Close before.
May be used, AnalysisStatus with StudyName ?
Because, in the Job manager, I have 3 server and four job launch all the time. With AnalysisStatuts(0) , I can't distinguish the different job.
Regards
Romain GUY
Hi,
right, StudyDoc.AnalysisStatus(0) check the status of the active study in Synergy.
If closed, it will fail, as no available active study.
I believe you have to use another approach. To find status of jobs from job manager.
Look up Job Class Reference in API Help.
But something like this:
Set JobManager = Synergy.JobManager()
Jobs starts such as:
i = 1
Number_Of_Jobs = JobManager.NumberOfJobs
Set job = JobManager.GetJob(i)
where you count through jobs in job server.
Job_ModelName = Job.ModelName()
JobStudyName = Left(Job_ModelName, Len(Job_ModelName) - 4)
compare study names and find
Job_Status = Job.Status()
You have to code above to suit your macro.
Regards,
Berndt
Hi,
I understand what you want to do. And I have make this.
But now, if I use :
Set JobManager = Synergy.JobManager()
I can't use AnalysisStatus because you can only use this function with Studydoc.
How I can find the time when my study is finish without AnalysisStatus ?
Private Sub Btndeb_Click() Dim rep As String rep = "Completed" Dim a As String Dim i As Single Dim Number As Single Dim Name As String 'launch the Flow analysis Set Synergy = CreateObject("synergy.Synergy") Synergy.SetUnits "Metric" Set StudyDoc = Synergy.StudyDoc() StudyDoc.AnalysisSequence "Flow" Set StudyDoc = Synergy.StudyDoc() StudyDoc.AnalyzeNow False, True 'Take the name of the study Dim StudyName As String Set StudyDoc = Synergy.StudyDoc() StudyName = StudyDoc.StudyName StudyName = Left(StudyName, Len(StudyName) - 4) StudyDoc.Close 'Find the number of study i = 1 Set JobManager = Synergy.JobManager() Number = JobManager.NumberOfJobs 'Find the good study For i = 1 To Number Set Job = JobManager.GetJob(i) Job_ModelName = Job.ModelName() Name = Left(Job_ModelName, Len(Job_ModelName) - 4) If Name = StudyName Then GoTo ici i = i + 1 Next ici: 'Wait the end of the flow analysis Do Set JobManager = Synergy.JobManager() a = JobManager.AnalysisStatus(i)Loop While a <> rep 'Open the study Set Project = Synergy.Project Project.OpenItemByName StudyName, "Study" 'Launch the Fill/Pack/Warp analysis Set StudyDoc = Synergy.StudyDoc() StudyDoc.AnalysisSequence "Flow|Warp" Set StudyDoc = Synergy.StudyDoc() StudyDoc.AnalyzeNow False, True StudyDoc.Close End Sub
Regards,
Romain GUY
Hi,
you can get the job status from job.
For job "i" such as:
Set Job = JobManager.GetJob(i)
Job_ModelName = Job.ModelName()
Job_Status = Job.Status()
For the job you check the status, until job no longer in job manager, meaning status is nothing.
Something like this:
Do 'Find the number of study i = 1 Set JobManager = Synergy.JobManager() Number = JobManager.NumberOfJobs Job_Status ="" 'Find the good study While (i < Number + 1) Set Job = JobManager.GetJob(i) Job_ModelName = Job.ModelName() Name = Left(Job_ModelName, Len(Job_ModelName) - 4) If Name = StudyName Then Job_Status = Job.Status() Else Job_Status ="" End If i = i + 1 Wend ' you can wait to loop to check status ' Application.Wait(Now + TimeValue("0:00:10")) ' or ' wscript.sleep 3000 ' wait 3s, 3000ms Loop While Job_Status <> ""
Hope this helps.
Regards,
Berndt
Hi
Ok, I understand !
I did change and now he run. But I can't put "Application.Wait(Now + TimeValue("0:00:10")) " in the loop because if the calcul finish when the application wait, the calcul diseapear in the Job Manager and the loop loose the Completed Status.
At the end , I obtained :
Private Sub Btndeb_Click() Dim rep As String rep = "Completed" Dim a As String Dim i As Single Dim Number As Single Dim Name As String Dim Job_Status As String Dim Job_ModelName As String rep = "Completed" 'launch the Flow analysis Set Synergy = CreateObject("synergy.Synergy") Synergy.SetUnits "Metric" Set StudyDoc = Synergy.StudyDoc() StudyDoc.AnalysisSequence "Flow" Set StudyDoc = Synergy.StudyDoc() StudyDoc.AnalyzeNow False, True 'Take the name of the study Dim StudyName As String Set StudyDoc = Synergy.StudyDoc() StudyName = StudyDoc.StudyName StudyName = Left(StudyName, Len(StudyName) - 4) StudyDoc.Close Do 'Find the number of study i = 1 Set JobManager = Synergy.JobManager() Number = JobManager.NumberOfJobs Job_Status = "" 'Finf the good study While (i < Number + 1) Set Job = JobManager.GetJob(i) Job_ModelName = Job.ModelName() Name = Left(Job_ModelName, Len(Job_ModelName) - 4) If Name = StudyName Then Job_Status = Job.Status() GoTo ici Else Job_Status = "" End If i = i + 1 Wend Loop While Job_Status <> "" ici: Do Job_Status = Job.Status() Loop While Job_Status <> rep 'Open the study Set Project = Synergy.Project Project.OpenItemByName StudyName, "Study" 'Launch the Fill/Pack/Warp analysis Set StudyDoc = Synergy.StudyDoc() StudyDoc.AnalysisSequence "Flow|Warp" Set StudyDoc = Synergy.StudyDoc() StudyDoc.AnalyzeNow False, True StudyDoc.Close End Sub
I am grateful for your help
See you soon on the forum
Regards
Romain GUY
Hi,
thank you. Just some comments.
I think the reason is you look for "Completed".
I mean, when job is completed it is no longer in Job Manager, and when job is completed the job status will be empty " ".
That is why job status also is set to empty "", when job is no longer in job manager.
I am not sure if it interfere with other things you do, but I think you can remove the ici exit, and second Do-loop.
Also, you might need to add a little wait time, but I am not sure.
I think the job will start before you close study, so the job_status will hold data.
Otherwise you can add a short wait.
Suggestion:
Application.Wait(Now + TimeValue("0:00:10")) '*** Add this line to get the job some time to start, if needed Do 'Find the number of study i = 1 Set JobManager = Synergy.JobManager() Number = JobManager.NumberOfJobs Job_Status = "" 'Finf the good study While (i < Number + 1) Set Job = JobManager.GetJob(i) Job_ModelName = Job.ModelName() Name = Left(Job_ModelName, Len(Job_ModelName) - 4) If Name = StudyName Then Job_Status = Job.Status() GoTo ici '*** Remove this line Else Job_Status = "" End If i = i + 1 Wend Application.Wait(Now + TimeValue("0:00:10")) '*** Add this line for wait Loop While Job_Status <> "" ici: '*** Remove this line Do '*** Remove this line Job_Status = Job.Status() '*** Remove this line Loop While Job_Status <> rep '*** Remove this line , do not need to check rep "Completed"
If you are all set with your script as is, you can ignore my suggestions.
Regards,
Berndt
Hi,
Ok , I have test this code before but without the Application.wait before close the study. And he didn't work.
Now, with this line, it's ok.
Thank you, for this suggestions because it's not good to have one exit (goto) in one loop.
Thanks for all
Regards
Romain GUY
Hello everybody.
i have a big problem. I am trying to execute a macro which i recorded and after recording i changed it.
First of all, i could not find a good documentation to write a macro. Of course there are some examples for API in help however they are not enough to learn how to write a macro or which functions can be used for moldflow. Can anybody show me a way to learn it, i tried a bit through some forums and VBscripts but with these i cannot reach my goal.
Second of all i have written a macro (see below or attachment) and i want to export my results after solving automatically by the macro. However this cannot be performed. Before its started to run, the macro tried to save the results but becuase there are no results at this time, it cannot save the results.
The Problem is in this case, i think, that analysis must be finished and after that it must export the data, how can i do that. I tried with AnalsisStatus but it did not work, and with Job.Status, it although did not work.
SetLocale("en-us")
Dim Synergy
Set Synergy = CreateObject("synergy.Synergy")
Synergy.SetUnits "Metric"
Dim rep
rep = "Completed"
Dim Job_Status
Set ImpOpts = Synergy.ImportOptions()
ImpOpts.MeshType "Midplane"
ImpOpts.Units ""
ImpOpts.MDLMesh True
ImpOpts.MDLSurfaces False
ImpOpts.UseMDL False
ImpOpts.MDLKernel ""
ImpOpts.MDLAutoEdgeSelect True
ImpOpts.MDLChordAngleSelect False
ImpOpts.MDLChordAngle 0
ImpOpts.MDLContactMeshType "Precise match"
ImpOpts.MDLSliverRemoval False
Set Project = Synergy.Project()
Synergy.ImportFile "C:\Users\Public\Documents\Autodesk\Simulation Moldflow Synergy 2015\tutorial\cushion_3d.sdy", ImpOpts, False
Set MatSel = Synergy.MaterialSelector()
MatSel.Select "SABIC Innovative Plastics US, LLC.21000.udb", "System", 7223, 0
Set BoundaryConditions = Synergy.BoundaryConditions()
Set Vector = Synergy.CreateVector()
Set EntList = BoundaryConditions.CreateEntityList()
EntList.SelectFromString "N947 "
Vector.SetXYZ -0, 0, 1
Set EntList_1 = BoundaryConditions.CreateNDBC(EntList, Vector, 40000, Nothing)
Set StudyDoc = Synergy.StudyDoc()
StudyDoc.AnalyzeNow True, True
Set JobManager = Synergy.JobManager()
Set Job = JobManager.GetJob(1)
Job_Status = Job.Status()
If rep = Job_Status Then
Set PlotManager = Synergy.PlotManager()
Set Plot = PlotManager.CreatePlotByDsID2(4009, 7)
Plot.SetSmoothShading True
Plot.SetEdgeDisplay 1
Plot.SetPlotMethod 128
Set Viewer = Synergy.Viewer()
Set PlotManager_1 = Synergy.PlotManager()
Set Plot_1 = PlotManager_1.FindPlotByName2("Fill time", "Fill time")
Set Viewer_1 = Synergy.Viewer()
Viewer_1.HidePlot Plot_1
Viewer.ShowPlot Plot
Set Viewer = Synergy.Viewer()
Set Plot = Viewer.ActivePlot()
Plot.SaveResultInPatran "C:\moj6.ele"
End If