Create a facing operation

Create a facing operation

janHUUUQ
Participant Participant
560 Views
2 Replies
Message 1 of 3

Create a facing operation

janHUUUQ
Participant
Participant

I am trying to better understand how to create operations using the API. A great example is Manufacturing Workflow API Sample . It is a bit complex and I try to create a minimal facing operation example. Here is my code so far:

def create_facing(setup : adsk.cam.Setup, tool : adsk.cam.Tool) -> adsk.cam.OperationBase:
    tool_type = tool.parameters.itemByName('tool_type').value.value 
    expected_tool_types = ["face mill", "flat end mill"]
    if not tool_type in expected_tool_types:
        raise Exception(f'Unexpected tool type. Expected: {expected_tool_types}. Got:{tool_type}')

    input = setup.operations.createInput('face') # strategy
    input.tool = tool
    input.displayName = 'My Face Operation'       
    preset = tool.presets.add()
    preset.name = 'My Preset name'
    preset.parameters.itemByName('tool_spindleSpeed').expression = "4999 rpm"
    preset.parameters.itemByName('tool_feedCutting').expression = "11 in/min"

    # create a face operation input and set the parameters.
    input.toolPreset = preset # assign created preset
    input.displayName = 'Face Operation'       

    # add the operation to the setup
    op : adsk.cam.OperationBase = setup.operations.add(input)
    return op

If I run it, I get:

janHUUUQ_0-1689583544654.png

So something is wrong with my tool parameters. If I open and close the operation in the GUI without editing anything, all issues disappear. Apparently, fusion fixes the parameters:

janHUUUQ_1-1689583658020.png

Here are my questions:

* What is the meaning of the error messages? What does "different value with level 1" mean? It sounds like there are conflicting definitions for a parameter? How to debug this?

* It seems in the GUI fusion magically resolves the parameter issues. Does it assign some default values? Is there a way to assign defaults for all parameters in the API?

* Aside: Here the preset I create is added to the tool. I am not sure I want that, can it have side effects in other areas of the program? Is there a way to create a fresh preset without adding it to the tool?

0 Likes
561 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

Hi @janHUUUQ -San.

 

I used the create_facing function you published and tried it with simple data and no error occurred.
Is it possible to publish an f3d file that can reproduce the error?

Message 3 of 3

jan_weidner
Contributor
Contributor

Thanks a lot @kandennti! I was not able to reproduce the error myself, so maybe I brought my fusion into a weird state. If I can reproduce, I will post an example.