Save in Mechanical with script

M
M Member, Employee Posts: 241
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?

Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 456
    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 25 Likes 10 Comments First Anniversary
    ✭✭✭✭
    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.