Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How to delete a part

2544173825
Enthusiast

How to delete a part

2544173825
Enthusiast
Enthusiast

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!

0 Likes
Reply
Accepted solutions (1)
305 Views
2 Replies
Replies (2)

kandennti
Mentor
Mentor
Accepted solution

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()))
0 Likes

2544173825
Enthusiast
Enthusiast

Thanks!

0 Likes