Finding Child Components

Finding Child Components

Anonymous
Not applicable
1,154 Views
2 Replies
Message 1 of 3

Finding Child Components

Anonymous
Not applicable

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

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

marshaltu
Autodesk
Autodesk
Accepted solution

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 Developer
>
0 Likes
Message 3 of 3

Anonymous
Not applicable

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.