Reorder operations in setup

Reorder operations in setup

echatzief
Advocate Advocate
777 Views
4 Replies
Message 1 of 5

Reorder operations in setup

echatzief
Advocate
Advocate

Hi, hope you're doing great!

I am creating a setup via the api, which contains multiple (x) operations.

I am aware of the fact that I can assign operations to my setup in a different way, thus changing the order of the final operations to the setup, but apparently that is not the desired way to achieve my goal.

I'd appreciate if anyone can inform me about the possibility of changing the order of the operations to my setup after them being assigned to it.

Thank you in advance!

0 Likes
778 Views
4 Replies
Replies (4)
Message 2 of 5

echatzief
Advocate
Advocate

Is there a chance it may not be possible?

Thank you!

0 Likes
Message 3 of 5

BrianEkins
Mentor
Mentor

It's not currently possible, but with all of the work that's been going on with the CAM API, I hope it's coming soon.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 5

kandennti
Mentor
Mentor

Hi @echatzief -San.

 

I don't know if this is very limited and useful due to lack of functionality, but I have created a sample using a template.

 

In the attached f3d file, the operations are created in the order of the red marks with the largest tool diameter, but when the script is executed, the order is changed to the green ones.

1.png

# Fusion360API Python script

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

THIS_DIR = pathlib.Path(__file__).resolve().parent

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

        camObj: cam.CAM = get_cam_product()

        sorted_by_diameter(camObj.setups[0])

        camObj.generateAllToolpaths(True)

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


def sorted_by_diameter(setup: cam.Setup) -> None:
    if setup.operations.count < 2: return

    # create dict
    opeLst = []
    ope: cam.Operation = None
    for ope in setup.operations:
        tool: cam.Tool = ope.tool
        dia = tool.parameters.itemByName(
            "tool_diameter"
            ).value.value
        
        opeLst.append(
            {
                "dia": dia,
                "ope": ope
            }
        )

    # sort
    sortedOpeLst = sorted(opeLst, key = lambda x:x["dia"])

    # export template
    template = cam.CAMTemplate.createFromOperations(
        [d["ope"] for d in sortedOpeLst]
    )

    # import template
    cloneOpes = setup.createFromCAMTemplate(template)

    # set parameter
    clone: cam.Operation 
    for clone, sortedDict in zip(cloneOpes, sortedOpeLst):
        originalOpe: cam.Operation = sortedDict["ope"]
        originalPrm: cam.CAMParameter = originalOpe.parameters.itemByName('holeFaces')

        clonePrm: cam.CAMParameter = clone.parameters.itemByName('holeFaces')

        clonePrm.value.value = originalPrm.value.value

        # remove original operation
        originalOpe.deleteMe()


def get_cam_product() -> cam.CAM:
    app: core.Application = core.Application.get()
    activete_cam_env()

    return app.activeProduct


def activete_cam_env() -> None:
    app: core.Application = core.Application.get()
    ui: core.UserInterface = app.userInterface

    camWS: core.Workspace = ui.workspaces.itemById('CAMEnvironment') 
    camWS.activate()

 

In fact, the operations are created in the template and the original ones are deleted, not reordered.

 

I haven't checked exactly, but there are some things that are not recorded when the template is created.
In the attached file, I have set HoleFaces in the geomatry tab for Drill only.

1.png

The parameters are different for each type of operation, so you may need to change the process for each type.
Also, if you are using CAD elements in the Heights tab, you may need to set them.

 

0 Likes
Message 5 of 5

boopathi.sivakumar
Autodesk
Autodesk

Currently it is not possible to change the Order of operations after it has been created. But which is something the team is aware of and working on it.


Boopathi Sivakumar
Senior Technology Consultant