Expand a setup from the API

Expand a setup from the API

jan_weidner
Contributor Contributor
530 Views
2 Replies
Message 1 of 3

Expand a setup from the API

jan_weidner
Contributor
Contributor

In Fusion360 I can expand and collapse setups by clicking on the |> icon next to them:

jan_weidner_0-1722580920800.png

 

Can I also expand and collapse from the API?

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

kandennti
Mentor
Mentor
Accepted solution

Hi @jan_weidner -San.

 

I found text commands to expand and collapse.

This is an example of collapsing all Setup, not Setups.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion
import adsk.cam as cam

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

        camObj: cam.CAM = app.activeProduct

        sels: core.Selections = ui.activeSelections
        sels.clear()

        for setup in camObj.setups:
            sels.add(setup)
            app.executeTextCommand(u"NaNeuCAMUI.CollapseAllChildren")
            sels.clear()

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


The deployment requires a little ingenuity because it all unfolds.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion
import adsk.cam as cam

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

        camObj: cam.CAM = app.activeProduct

        sels: core.Selections = ui.activeSelections
        sels.clear()

        for setup in camObj.setups:
            sels.add(setup)
            app.executeTextCommand(u"NaNeuCAMUI.ExpandAllChildren")
            sels.clear()
            for ope in setup.operations:
                sels.add(ope)
                app.executeTextCommand(u"NaNeuCAMUI.CollapseAllChildren")
                sels.clear()

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

jan_weidner
Contributor
Contributor

Wow it would never occured to me to it like this, thanks!