How to create a new mechanical system from the Mechanical scripting window without crashing?

Nick Ramseyer
Nick Ramseyer Member Posts: 25
10 Comments Name Dropper
**

I am currently trying to execute a journaling command that creates a new analysis system in the project page. I am running the command from the mechanical scripting window:
ExtAPI.Application.ScriptByName('journaling').ExecuteCommand(command)

The command is set up to create a new analysis system next to the one I am currently viewing and looks like this:
command = """\n template1 = GetTemplate( TemplateName="Static Structural", Solver="ANSYS") system1 = GetSystem(Name="SYS") system2 = template1.CreateSystem( Position="Right", RelativeTo=system1) """

The problem I am having is that running this script from the mechanical scripting window seems to lock up and crash the software. If I run the same code from a wbjn file from the workbench project window it works fine, but executing it from Mechanical causes the crash.

Does anyone have any thoughts on how to fix this issue and run a journaling script that creates a new system from the mechanical scripting ExtAPI? I suspect it has something to do with threads and processes, but I don't know how to control what is happening when a journal is called from the mechanical scripting window.

Thank you!

Best Answer

Answers

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 361
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    I have come across issues like this and I would generally recommend against running scripts that will modify the Workbench project from the Mechanical API.

    Could you create the new analysis per the Mechanical API (no jscript, just supported pythonic API of Mechanical), then run a clean up script to only move the systems on the project schematic for the layout you want?

  • Nick Ramseyer
    Nick Ramseyer Member Posts: 25
    10 Comments Name Dropper
    **

    I'm not sure it's possible to do everything I am looking to implement with the available mechanical api. Essentially, I am trying to automate the creation of analysis system and importing of a geometry file to that system. I then want to set up the analysis using some automation scripts. I am not aware of an ability in the api to create a new analysis system that isn't already tied to the model of the existing window.

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 361
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    @Nick Ramseyer , You are correct, I was thinking you wanted to make a new analysis system for the current mechanical model.

    Is there a reason you don't hop over to Workbench and run the script from that application? You could send API calls to the existing Mechanical session, create new systems, and do the setup.

    I can understand why you may be in Mechanical and want the workflow controlled from there, but in your case I would recommend that you do this automation from Workbench for the problems you have found.

  • Nick Ramseyer
    Nick Ramseyer Member Posts: 25
    10 Comments Name Dropper
    **

    I think the motivation here is in creating an ACT workflow to deploy across an organization where there is a central location where all of the buttons can live. I don't believe I can add a button the workbench project page and having users manually run the script is not acceptable. Having the buttons in mechanical is a decent solution as everything is in one place. Now I'm mostly curious why this is a challenge as there are similar behaviors that can be implemented such as interacting with the engineering data:

    https://discuss.ansys.com/discussion/comment/2278#Comment_2278

    Although if you have the engineering data tab open while interacting with it through journaling it will also cause a crash. So, my guess is that the scripting cannot interact with an open UI process.

    Thank you for the feedback! This is a fairly niche thing. I do think as people get used to using the scripting features in mechanical, they are going to eventually want to automate their entire engineering process and having a workaround for this would allow that to be done inside of mechanical instead of creating a wizard.