ExtractBOM "Addin" - Add Description & Material Properties

ExtractBOM "Addin" - Add Description & Material Properties

isocam
Collaborator Collaborator
847 Views
2 Replies
Message 1 of 3

ExtractBOM "Addin" - Add Description & Material Properties

isocam
Collaborator
Collaborator

Can anybody help???

 

I need the standard "ExtractBOM", that is downloaded with Fusion 360 modified to show the "Description & Material Property" of each part. I do not need the "Volume" property.

 

Has anybody modified the Addin to do this?

 

Many thanks in Advance!!!!

 

Darren

0 Likes
848 Views
2 Replies
Replies (2)
Message 2 of 3

marshaltu
Autodesk
Autodesk

Hello,

 

Please try the following codes and see if they are what you want.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback

def spacePadRight(value, length):
    pad = ''
    if type(value) is str:
        paddingLength = length - len(value) + 1
    else:
        paddingLength = length - value + 1
    while paddingLength > 0:
        pad += ' '
        paddingLength -= 1

    return str(value) + pad

def walkThrough(bom):
    mStr = ''
    for item in bom:
        mStr += spacePadRight(item['name'], 25) + str(spacePadRight(item['instances'], 15)) + str(spacePadRight(item['material'], 25)) + str(item['description']) + '\n'
    return mStr

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        title = 'Extract BOM'
        if not design:
            ui.messageBox('No active design', title)
            return

        # Get all occurrences in the root component of the active design
        root = design.rootComponent
        occs = root.allOccurrences
        
        # Gather information about each unique component
        bom = []
        for occ in occs:
            comp = occ.component
            jj = 0
            for bomI in bom:
                if bomI['component'] == comp:
                    # Increment the instance count of the existing row.
                    bomI['instances'] += 1
                    break
                jj += 1

            if jj == len(bom):             
                # Add this component to the BOM
                bom.append({
                    'component': comp,
                    'name': comp.name,
                    'instances': 1,
                    'material': comp.material.name if comp.material else '',
                    'description': comp.description
                })

        # Display the BOM
        title = spacePadRight('Name', 25) + spacePadRight('Instances', 15) + spacePadRight('Material', 25) + 'Description\n'
        msg = title + '\n' + walkThrough(bom)
        
        ui.messageBox(msg, 'Bill Of Materials')

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


Marshal Tu
Fusion Developer
>
0 Likes
Message 3 of 3

Anonymous
Not applicable

Apologies for reviving an old thread. I am looking for help regarding adding length, width and thickness to the extractBOM popup. Have tried reading and hacking at the python code to no avail.

 

Also, is there a way to have extractBOM as a toolbar button in Fusion360, or at the very least a shortcut?

 

Many thanks

0 Likes