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: 

Assembly traversal using recursion API Sample - Adding "Instances", "Description", "Material" & "Description"

1 REPLY 1
SOLVED
Reply
Message 1 of 2
isocam
96 Views, 1 Reply

Assembly traversal using recursion API Sample - Adding "Instances", "Description", "Material" & "Description"

Can anybody help?

 

Please see the following website for the "Traverse Assembly" sample:

 

Fusion 360 Help | Assembly traversal using recursion API Sample | Autodesk

 

Does anybody know how to add "Instances", "Description", "Material" & "Parent Folder" to the output?

 

Many thanks in advance!

 

Kind Regards

 

Darren

 

 

1 REPLY 1
Message 2 of 2
Jorge_Jaramillo
in reply to: isocam

Hi @isocam ,

 

It could be something like this:

 

def traverseAssembly(occurrences: adsk.fusion.Occurrences, currentLevel: int, inputString: str, parent: str = '') -> str:
    for i in range(occurrences.count):
        occ = occurrences.item(i)
        materials = [body.material.name for body in occ.bRepBodies if body.material]
        inputString += f"{' '*(currentLevel * 5)}{occ.name};{occ.childOccurrences.count};{occ.component.description};{materials};{parent}" + "\n"
        if occ.childOccurrences:
            inputString = traverseAssembly(occ.childOccurrences, currentLevel + 1, inputString, occ.fullPathName)
    return inputString

 

I use a semicolon here to separate data items.

 

Hope this help.

 

Regards,

Jorge

 

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