import adsk.core import adsk.fusion from collections import defaultdict # Fusion 360 parts list with dimensions # API manual https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-C1545D80-D804-4CF3-886D-9B5C54B2D7A2 def run(context): app = adsk.core.Application.get() ui = app.userInterface product = app.activeProduct design = adsk.fusion.Design.cast(product) units = design.unitsManager.defaultLengthUnits # Get the root component of the active design. rootComp = design.rootComponent # Get occurences from root components = [rootComp.occurrences[i].component for i in range( rootComp.occurrences.count)] components = [rootComp] + components total_lengths = defaultdict(float) total_counts = defaultdict(int) dialog_str = '' dialog_str += '' dialog_str += '' dialog_str += '' dialog_str += '' dialog_str += f'' dialog_str += f'' dialog_str += f'' dialog_str += '' not_visible_count = 0 for subcomp in components: for bidx in range(0, subcomp.bRepBodies.count): body = subcomp.bRepBodies.item(bidx) if not body.isVisible: not_visible_count += 1 continue dimvector = body.boundingBox.minPoint.vectorTo( body.boundingBox.maxPoint).asPoint() dims = sorted(dimvector.asArray()) formx = product.unitsManager.formatInternalValue( dims[0], units, False) formy = product.unitsManager.formatInternalValue( dims[1], units, False) formz = product.unitsManager.formatInternalValue( dims[2], units, False) dialog_str += '' dialog_str += f'' dialog_str += f'' dialog_str += f'' dialog_str += f'' dialog_str += f'' dialog_str += '' key_length = f'{formx} x {formy}' total_lengths[key_length] += float(formz) key_count = f'{formx} x {formy} x {formz}' total_counts[key_count] += 1 dialog_str += '
ComponentBodyx ({units})y ({units})z ({units})
{subcomp.name}{body.name}{formx}{formy}{formz}
' dialog_str += '

Total counts

' dialog_str += '' dialog_str += '' dialog_str += '' dialog_str += '' for key_count in sorted(total_counts.keys()): dialog_str += f'' dialog_str += f'' dialog_str += f'' dialog_str += '' dialog_str += '
DimensionsCount
{key_count}{total_counts[key_count]}
' dialog_str += '

Total lengths

' dialog_str += '' dialog_str += '' dialog_str += f'' dialog_str += f'' dialog_str += '' for key_length in sorted(total_lengths.keys()): dialog_str += f'' dialog_str += f'' dialog_str += f'' dialog_str += '' dialog_str += '
Dimensions ({units})Total length ({units})
{key_length}{total_lengths[key_length]}
' if not_visible_count: dialog_str += f'

Note: {not_visible_count} hidden {"body" if not_visible_count == 1 else "bodies"} excluded from the lists' ui.messageBox(dialog_str, 'Total materials used', adsk.core.MessageBoxButtonTypes.OKButtonType, adsk.core.MessageBoxIconTypes.InformationIconType) print(dialog_str)