Save in Mechanical with script

M
M Member, Employee Posts: 244
50 Answers 100 Comments 100 Likes Second Anniversary
✭✭✭✭
edited June 2023 in Structures

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?

Best Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 468
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    Answer ✓

    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")
    
  • Chemsdine CHEMAI
    Chemsdine CHEMAI Member, Employee Posts: 201
    100 Likes 100 Comments Second Anniversary Ansys Employee
    ✭✭✭✭
    Answer ✓

    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)

  • Aria
    Aria Member, Employee Posts: 67
    25 Answers Second Anniversary 25 Likes 10 Comments
    ✭✭✭✭
    Answer ✓

    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.

Answers

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 214
    100 Comments 25 Answers Second Anniversary 25 Likes
    ✭✭✭✭

    Expanding on script example from @Chemsdine CHEMAI , we can also use the below to use save as option instead of save.

    cmd="""DS.Script.doFileSaveProjectAs()"""
    ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(cmd)