Hi @bruce9PYQ9 .
I tried to find an alternative.
I tried the Occurrences.addExistingComponent method, but it was not what I wanted.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-a2efccd6-ac40-465b-811d-e5d0266d1c62
I tried other methods, but this was the one that seemed to work now.
# Fusion360API Python script
import traceback
import adsk.fusion
import adsk.core
def run(context):
ui: adsk.core.UserInterface = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
des: adsk.fusion.Design = app.activeProduct
root: adsk.fusion.Component = des.rootComponent
targetOcc: adsk.fusion.Occurrence = root.allOccurrences.itemByName('Part_C:1')
if targetOcc:
moveToRootComponent(targetOcc)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def moveToRootComponent(
occ: adsk.fusion.Occurrence) -> adsk.fusion.Occurrence:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
sels: adsk.core.Selections = ui.activeSelections
sels.clear()
sels.add(occ)
app.executeTextCommand(u'NuCommands.CutCmd')
root: adsk.fusion.Component = app.activeProduct.rootComponent
sels.clear()
sels.add(root)
app.executeTextCommand(u'NuComponents.PasteCmd')
app.executeTextCommand(u'NuCommands.CommitCmd')
return root.occurrences[-1]