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: 

How to delete a part

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
2544173825
142 Views, 2 Replies

How to delete a part

I imported a part into Fusion 360 via app.importManager.importToTarget2, if I want to delete this part from the software via Fusion 360 API, how should I do it!

2 REPLIES 2
Message 2 of 3
kandennti
in reply to: 2544173825

Hi @2544173825 .

 

Modify the path and try this.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        path = r'C:\temp\7778_3a9748b3_0005_1.smt'

        importMgr: adsk.core.ImportManager = app.importManager
        smtOpt: adsk.core.SMTImportOptions = importMgr.createSMTImportOptions(path)
        occs = importMgr.importToTarget2(smtOpt, root)
        ui.messageBox('import')

        for occ in occs:
            try:
                doc: adsk.fusion.FusionDocument = occ.component.parentDesign.parentDocument
                doc.close(False)
            except:
                pass
        ui.messageBox('remove document')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Message 3 of 3
2544173825
in reply to: kandennti

Thanks!

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