Save in Mechanical with script

M
M Member, Employee Posts: 199
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
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: 389
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    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
    First Anniversary Ansys Employee Solution Developer Community of Practice Member 5 Likes
    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: 64
    First Anniversary Ansys Employee First Answer Name Dropper
    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.