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: 

Get Part Attributes When Exporting A BOM Using A Python Script

3 REPLIES 3
Reply
Message 1 of 4
isocam
178 Views, 3 Replies

Get Part Attributes When Exporting A BOM Using A Python Script

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

3 REPLIES 3
Message 3 of 4
isocam
in reply to: kandennti

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

Message 4 of 4
BrianEkins
in reply to: isocam

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

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