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

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

isocam
Collaborator Collaborator
411 Views
1 Reply
Message 1 of 2

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

isocam
Collaborator
Collaborator

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

 

 

0 Likes
Accepted solutions (1)
412 Views
1 Reply
Reply (1)
Message 2 of 2

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

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