Create New Component Using API

Create New Component Using API

isocam
Collaborator Collaborator
2,117 Views
1 Reply
Message 1 of 2

Create New Component Using API

isocam
Collaborator
Collaborator

Can anybody help???

 

Is it possible, using Fusion 360 API, to capture the "Create New Component" function?

 

At present, I have to manually input a name for the new component. If the assembly is, for example, 1000 every time I right mouse click "Create New Component", can the part number be the assembly number + 1.

 

For example,

 

1000

 

Part Numbers 1000-001, 1000-002, 1000-003 etc

 

Many thanks in advance!!!!

 

Darren

0 Likes
2,118 Views
1 Reply
Reply (1)
Message 2 of 2

marshaltu
Autodesk
Autodesk

Hello,

 

The following sample demonstrates how to create new component and set "name" or "part number" by API.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback

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

    design = adsk.fusion.Design.cast(app.activeProduct)
    root = design.rootComponent
    
    for i in range(10):
        occ = root.occurrences.addNewComponent(adsk.core.Matrix3D.create())
        occ.component.name = 'My Component{}'.format(i)

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


Marshal Tu
Fusion Developer
>