How to delete a cam operation ?

How to delete a cam operation ?

maurizio_manzi
Advocate Advocate
657 Views
4 Replies
Message 1 of 5

How to delete a cam operation ?

maurizio_manzi
Advocate
Advocate

Hello,

I can add a cam operation in a setup with:

operationInput = setup.operations.createInput('pocket2d')
op_2Dpocket = setup.operations.add(operationInput)
But how can I delete a cam operation from setup, that are no more needed ?
Best regards
Maurizio
0 Likes
Accepted solutions (1)
658 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor

Hi @maurizio_manzi .

 

The Operation object did not have a deleteMe method, so I looked for another way.

Since there was a deleteEntities method in the Cam object, I thought I could delete it by doing the following, but I got an error.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.cam as cam

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

        camObj: cam.CAM = app.activeProduct

        setup: cam.Setup = camObj.setups[0]
        ope: cam.Operation = setup.operations[0]

        objs: core.ObjectCollection = core.ObjectCollection.create()
        # objs.add([ope]) # NG
        objs.add(ope)

        # https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-3C5139A6-8639-4466-8DB5-008B721BC059
        camObj.deleteEntities(objs)

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

 

I may be missing something, but the only thing I can think of is to set isSuppressed = True.

0 Likes
Message 3 of 5

jeff.pek
Community Manager
Community Manager
Accepted solution

The ability to delete an operation via the API is coming as of the next Fusion update, currently targeted at late May.

  Jeff

Message 4 of 5

en9y37
Advocate
Advocate

Hi all!

 

The camObj.deleteEntities(objs) method doesn't work yet. This error message is thrown when it's executed:

      RuntimeError: 5 : API Function not yet implemented

 

Is there any other know method to delete several setups, manufacturing models or operations at once? I mean not iterating through all the setups, manufacturing models and operations.

 

Thanks in advance.

0 Likes
Message 5 of 5

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

I tried to create a function that delete what camObj.deleteEntities(objs) should do and it worked.

You can use it meanwhile the deteleEntities() is implemented; after all, you can just replace it without any other changes.

It work with objects that have the deleteMe() method.

 

 

def test_delete_cam_oobject() -> None:

    def delete_cam_objects(oc: adsk.core.ObjectCollection) -> boolean:
        ret = True
        for obj in oc:
            try:
                ret |= obj.deleteMe()
            except:
                ret = False
        return(ret)

    cam: adsk.cam.CAM = doc.products.itemByProductType('CAMProductType')
    setup = cam.setups.item(0)
    operation = setup.operations.item(0)

    to_delete = adsk.core.ObjectCollection.create()
    to_delete.add(operation)
    to_delete.add(setup)

    app.log(f'{delete_cam_objects(to_delete)=}')

 

I hope this could help.

 

Regards,

Jorge Jaramillo