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

Issues deleting canvases

en9y37
Advocate

Issues deleting canvases

en9y37
Advocate
Advocate

Hi everyone.

 

I'm trying to delete canvases via API and I get quite a weird thing. The script seems to delete the canvases, and they are deleted from the occurrence indeed, but somehow, they remain in the timeline and don't look to be belonging to any component.

 

The canvases before executing the script:

en9y37_0-1724148883138.png

 

After the execution:

en9y37_1-1724148940360.png

 

Is there something I'm doing wrong or is this a bug?

 

Here I leave the code to reproduce the issue and the .f3d file with the canvases before the execution of the script.

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        rootComp = design.rootComponent
        
        deleteList:list[adsk.fusion.Canvas] = []
        for occ in rootComp.allOccurrences:
            component = occ.component
            for canvas in component.canvases:
                deleteList.append(canvas)
        
        for canvas in deleteList:
            canvas.deleteMe()
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

0 Likes
Reply
Accepted solutions (2)
303 Views
3 Replies
Replies (3)

kandennti
Mentor
Mentor
Accepted solution

Hi @en9y37 -San.

 

I have tried and can reproduce it.
This seems like a bug.

 

I tried deleting it using a text command instead.

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        rootComp = design.rootComponent
        
        deleteList:list[adsk.fusion.Canvas] = []
        for occ in rootComp.allOccurrences:
            component: adsk.fusion.Component = occ.component
            for canvas in component.canvases:
                canvas = canvas.createForAssemblyContext(occ)
                deleteList.append(canvas)

        sels: adsk.core.Selections = ui.activeSelections
        sels.clear()

        for canvas in deleteList:
            # canvas.deleteMe()
            sels.add(canvas)
        
        app.executeTextCommand(u"Commands.Start FusionDeleteCommand")
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
2 Likes

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

Since the two canvases are the last items in the timeline, I made a test deleting them from the timeline, like so:

    app.log(f'{des.timeline.count=}')
    des.timeline.markerPosition = des.timeline.count - 2
    des.timeline.deleteAllAfterMarker()
    app.log(f'{des.timeline.count=}')

It deleted both, the canvases and the items from the timeline.

 

Jorge_Jaramillo_0-1724166165442.png

 

It is, of course, a workaround while the bug get fixed.

 

Regards,

Jorge Jaramillo

 

2 Likes

en9y37
Advocate
Advocate

Thanks guys. Both workarounds will work somehow until this bug is fixed.

1 Like