Detect when the CAM Simulation environment is on

Detect when the CAM Simulation environment is on

ltomuta
Advisor Advisor
322 Views
3 Replies
Message 1 of 4

Detect when the CAM Simulation environment is on

ltomuta
Advisor
Advisor

I would like to hide/show a palette when the user starts/ends a CAM simulation but I could not figure out a way to be notified of the change. Any idea?

0 Likes
Accepted solutions (1)
323 Views
3 Replies
Replies (3)
Message 2 of 4

jeff.pek
Community Manager
Community Manager
Accepted solution

Hi -

You can probably use command execution events - https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-3922697A-7BF1-4799-9A5B-C8539DF57051#Execute... - to detect the launch of the command that opens the environment, and the event that closes it.

 

The launch command IDs are "IronSimulation" and "IronMachineSimulation". The "finish" command is "SimulationStop".

 

Jeff

Message 3 of 4

ltomuta
Advisor
Advisor

Worked like a charm. Thanks @jeff.pek !

0 Likes
Message 4 of 4

kandennti
Mentor
Mentor

Hi @ltomuta -San.

 

If you want to check in the middle of some process, you can check if ToolbarControl is displayed here.

1.png

# Fusion360API Python script

import traceback
import adsk.core as core

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface

        print(is_cam_simulation_working())

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def is_cam_simulation_working() -> bool:
    app: core.Application = core.Application.get()
    ui: core.UserInterface = app.userInterface

    panels: core.ToolbarPanels = ui.allToolbarPanels.itemById(
        "SimulationFinishPanel"
    )

    controlLst = filter(
        lambda c: c.id == "SimulationStop", panels.controls
    )

    return list(controlLst)[0].isVisible