Show Properties Box

isocam
Collaborator

Show Properties Box

isocam
Collaborator
Collaborator

Can anybody help?

 

I have the following Python script that works great if the Fusion 360 document is a single part (not an assembly).

 

import adsk.core, adsk.fusion, traceback

def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
des = app.activeProduct
root = des.rootComponent

# select brepbody
sels = ui.activeSelections
sels.add(root.bRepBodies[0])

# show props - textcommands
app.executeTextCommand(u'Commands.Start FusionPropertiesCommand')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Does anybody know how to modify the above so that it works on both a single part and an assembly?

 

Many thanks in advance!

 

Darren

0 Likes
Reply
216 Views
1 Reply
Reply (1)

Rushikesh.kadam
Autodesk
Autodesk

@isocam you need to get the body from the component when using an assembly. Here is the modified code of your version to select all the bodies present under root and individual components. 

 

import traceback, adsk.fusion, adsk.core
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = app.activeProduct
        root = des.rootComponent

        # select brepbody
        sels = ui.activeSelections
        for body in root.bRepBodies:
            sels.add(body)
        for component in root.allOccurrences:
            for body in component.bRepBodies:
                sels.add(body)
        

        # show props - textcommands
        app.executeTextCommand(u'Commands.Start FusionPropertiesCommand')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

If you want to just select the first body in the first component of the assembly you can simply use 

sels.add(root.allOccurrences[0].bRepBodies[0])

------------------------------------------------------------------------------------------------------------------------------

If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed.




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


0 Likes