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: 

ExtractBOM "Addin" - Add Description & Material Properties

2 REPLIES 2
Reply
Message 1 of 3
isocam
532 Views, 2 Replies

ExtractBOM "Addin" - Add Description & Material Properties

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

2 REPLIES 2
Message 2 of 3
marshaltu
in reply to: isocam

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 360 Developer
Autodesk, Inc.

Message 3 of 3
Dan.t02
in reply to: isocam

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

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