Running Secondary Script

Running Secondary Script

Anonymous
Not applicable
758 Views
2 Replies
Message 1 of 3

Running Secondary Script

Anonymous
Not applicable

Firstly, huge shoutout to @kandenntifor your enormous help and work into understand textCommands, you've helped me and my colleague Svitlana a LOT!

 

Is there a way to call another Fusion360 script from within a script? Or perhaps a way to alter my current workflow to prevent Fusion360 crashing?

I'm experiencing the following issue: 

I'm trying to use app.executeTextCommand to do the following sequence of steps:

- create a thermal simulation and switch to simulation menu

- load up a thermal loads menu  

For whatever reason, if I execute all of those commands separately within the TextCommand window in Fusion360, they work perfectly. However in script, Fusion360 immediately crashes if I try to open the thermal loads menu immediately after creating a thermal study. Here's the script that crashes:

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        app.executeTextCommand(u'Commands.Start CreateSimulationModelCommand')
        app.executeTextCommand(u'Commands.Start FinishSimplifyCommand')
        app.executeTextCommand(u'NuCommands.CommitCmd')
        #crashes right here VV if you comment the next two lines it works until then
        cmd = ui.commandDefinitions.itemById("SimThermalLoadConvectionCmd")
        cmd.execute()    

 

Here's the exact sequence I enter into the Txt environment within TextCommands that works perfectly:

Commands.Start CreateSimulationModelCommand
Ok
Commands.Start FinishSimplifyCommand
Ok
Commands.Start SimThermalLoadConvectionCmd
Ok

 

My solution at the moment is that I created two scripts. First script generates a thermal study and then prompts the user to manually run my second script. The second script switches into the simulation environment which has an active study and then pulls up the thermal loads menu. It achieves the goal but I really don't like the need for user interaction in such a small step. 

0 Likes
759 Views
2 Replies
Replies (2)
Message 2 of 3

OceanHydroAU
Collaborator
Collaborator

Disclaimer - I don't really know that stuff, but, it looks at first-glance like perhaps you need to wait for those executeTextCommand steps to complete?

 

Other ideas to try - perhaps run something else that "does nothing" in the middle of them (e.g. create a new blank sketch or something after each one) - the process of doing that might cause Fusion360 to run housekeeping or other tasks that might prevent the crash?

0 Likes
Message 3 of 3

kandennti
Mentor
Mentor

Hi @Anonymous .

 

I tried a few things.
Using a document that does not have a study, it was difficult to activate the simulation workspace.
 
We found that we could work around this by creating the simulation assets in advance, switching workspaces and creating studies.
However, to create the asset of the simulation, you need the document path, so you need to save it once.
 
import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        # get Document Path
        path = _app.executeTextCommand(u'Document.path')
        if path == 'Untitled':
            _ui.messageBox('Please save once!')
            return

        # Create Simulation Asset
        _app.executeTextCommand(u'AssetMgt.Create {} SimModelAssetType'.format(path))
        # _app.executeTextCommand(u'AssetMgt.Create {} SimCaseAssetType'.format(path))

        # activate Simulation WorkSpace
        simWs = _ui.workspaces.itemById('SimulationEnvironment')
        simWs.activate()

        # Create Thermal Steady
        _app.executeTextCommand(u'SimCommonUI.CreateStudy SimCaseThermalSteady')
        # _app.executeTextCommand(u'SimCommonUI.CreateGenStudy SimCaseThermalSteady')

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
 
The goal has not been reached.
I'm sure there will be many more difficulties in the future.
0 Likes