Save in Mechanical with script
A customer wouuld like to save their model with a script. They have found:
Ansys.ACT.Interfaces.UserInterface.IRenderer.ShowSaveDialog()
But the documentation is lacking.
Anyone have an experience with this command or how to get the save dialog to pop up with scripting?
Answers
-
You need the
UIRenderer
object from your project. This will work:ExtAPI.UserInterface.UIRenderer.ShowSaveDialog()
ExtAPI.UserInterface.UIRenderer.ShowSaveDialog.__doc__ 'ShowSaveDialog(self: UIRenderer, filter: str, folder: str) -> str \n' ExtAPI.UserInterface.UIRenderer.ShowSaveDialog(".txt", r"D:\Path\to\my\folder")
0 -
To save, you can use :
From Mechanical :
cmd="""DS.Script.doFileSaveProject()"""
ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(cmd)
From the project page, it can be found using the recording (“Save” command)
2 -
Running this following script asynchronously via journaling will save the WB project via Mechanical.
journalEngine = ExtAPI.Application.ScriptByName("journaling") journalEngine.ExecuteCommandAsync('Save(FilePath=r"C:\my_proj.wbpj", Overwrite = True)')
wbjn.ExecuteCommand runs the command synchronously meaning we make a call from Mechanical that waits for Workbench to respond, in this instance Workbench makes a call back to Mechanical and waits for it to respond. We end up in a deadlock, Mechanical is busy trying to execute the original command and Workbench can't actually save without Mechanical responding to it, which is why Mechanical crashes when using the synchronous method of injecting the WB commands.
2