Get Part Attributes When Exporting A BOM Using A Python Script

Get Part Attributes When Exporting A BOM Using A Python Script

isocam
Collaborator Collaborator
639 Views
3 Replies
Message 1 of 4

Get Part Attributes When Exporting A BOM Using A Python Script

isocam
Collaborator
Collaborator

Can anybody help?

 

I can set a Fusion 360 "part attribute" using the following Python script....

 

def SetPartType(PartType):
ui = None
try:
app = adsk.core.Application.get()

ui = app.userInterface

selectedComponent = adsk.fusion.Design.cast(app.activeProduct).rootComponent

compAttributes = selectedComponent.attributes

newAttribute = compAttributes.add('PartAttributes', 'Part: Type', PartType)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

And then, I can read the "part attribute" using the following Python script....

 

def GetPartType():
ui = None
try:
app = adsk.core.Application.get()

ui = app.userInterface

selectedComponent = adsk.fusion.Design.cast(app.activeProduct).rootComponent

compAttributes = selectedComponent.attributes

readAttribute = compAttributes.itemByName('PartAttributes', 'Part: Type')

PartType = readAttribute.value

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

 

How can I get the part attribute when exporting a BOM file using a Python Script?

 

def traverseAssembly(occurrences, currentLevel, OutputString):
app = adsk.core.Application.get()

ui = app.userInterface

for i in range(0, occurrences.count):
occ: adsk.fusion.Occurrence = occurrences.item(i)

PartNumber = re.split(' v\d+', occ.name)[0]

 

PartType = ???????

 

Many thanks in advance!

 

Darren

0 Likes
640 Views
3 Replies
Replies (3)
Message 3 of 4

isocam
Collaborator
Collaborator

kandennti,

 

I tried the flat pattern script, but nothing seemed to work.

 

I do not know what the Chinese writing means.

 

Could you please supply a new script, fully in english?

 

All I need is to create a "flat pattern" dxf file from a Fusion 360 sheet metal part

 

The dxf file, for testing purposes, just needs to be saved to the desktop,

 

Many thanks in advance!!!!

 

Darren

0 Likes
Message 4 of 4

BrianEkins
Mentor
Mentor

Give this a try:

def run(context):
    app = adsk.core.Application.get()
    ui = app.userInterface
    try:
        flatProduct: adsk.fusion.FlatPatternProduct = app.activeDocument.products.itemByProductType('FlatPatternProductType')
        if flatProduct is None:
            ui.messageBox('No flat pattern exists in the active document.')
            return

        flat = flatProduct.flatPattern
        if flat is None:
            ui.messageBox('No flat pattern exists in the active document.')
            return

        filename = 'C:/Temp/Test.dxf'
        flatExportOptions = flatProduct.exportManager.createDXFFlatPatternExportOptions(filename, flat)
        if flatProduct.exportManager.execute(flatExportOptions):
            ui.messageBox(f'Successfully exported flat pattern to: "{filename}"')
        else:
            ui.messageBox('Flat pattern export failed.')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes