Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Python - Export BOM File With "Full" Folder Path

isocam
Collaborator Collaborator
400 Views
1 Reply
Message 1 of 2

Python - Export BOM File With "Full" Folder Path

isocam
Collaborator
Collaborator

Can anybody help???

 

Please see the attached picture and Python script (I have changed the file name extension from "py" to "txt).

 

All I need is the script file updating so that it will output the folder path of a part that was inserted into an assembly.

 

For Example:

 

Say I have an assembly containing several parts. One of these parts has been inserted from the folder called "Purchased Parts" > "Bearings" (Please see the attached picture).

 

I need to add the folder path to the output, in the above case, this would be "Bearings".

 

Is the above possible?

 

Many thanks in advance!!!

 

Darren

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

BrianEkins
Mentor
Mentor
Accepted solution

Here's a modified version of your traverseAssembly function that gets the folder name and I believe should also get the quantity. I think there is still some tweaking to do to clean up the output.

 

def traverseAssembly(occurrences, currentLevel, inputString):
    for i in range(0, occurrences.count):
        occ: adsk.fusion.Occurrence = occurrences.item(i)
        PartNumber = re.split(' v\d+', occ.name)[0]
        PartDescription = occ.component.description

        doc: adsk.core.Document = occ.component.parentDesign.parentDocument
        if doc.dataFile:
            FolderName = doc.dataFile.parentFolder.name
        else:
            FolderName = 'Unsaved'

        PartQuantity = occ.sourceComponent.occurrencesByComponent(occ.component).count
        inputString += SpacePadRight(PartDescription, 77) + SpacePadRight(PartQuantity, 14) + SpacePadRight(FolderName, 41) + SpacePadRight(PartNumber, 53) + '\n'

        if occ.childOccurrences:
            inputString = traverseAssembly(occ.childOccurrences, currentLevel + 1, inputString)

    return inputString

tra 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes