Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Finding Child Components

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
nnamfoh
664 Views, 2 Replies

Finding Child Components

I need to access the child components of a component (often the root component). I need to create an object collection of all bodies in the parent and its children to edit the groups

2 REPLIES 2
Message 2 of 3
marshaltu
in reply to: nnamfoh

Hello,

 

The following script would demo how to get all bodies under root. Please let us know if you have other questions.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct) 
        root = design.rootComponent
        componentNameMap = {}
        componentNameMap[root.name] = root

        for occ in root.allOccurrences:
            subComp = occ.component
            componentNameMap[subComp.name] = subComp
        
        allbodies = adsk.core.ObjectCollection.create()
        for comp in list(componentNameMap.values()):
            for body in comp.bRepBodies:
                allbodies.add(body)
        
        ui.messageBox("Total {} bodies under root component".format(allbodies.count))

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


Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 3 of 3
hammadedesigns
in reply to: marshaltu

What am I supposed to do with this root?  I am new to Fusion 360 and really need to see the children of a feature so I know what may change or have issues.  Thanks in advance.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report