Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAM setup API parameters expression assign does not work?

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
danieleR9DDN
240 Views, 7 Replies

CAM setup API parameters expression assign does not work?

Hi, I'm trying to automate CAM setup parameters setting by API with Python.

I copy the sample that is in the API documentation in a new script ( https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2716A113-555D-41B0-8FC4-4FCD265434C4 ) but it seems does not work.

I'm able to control the name of the setup  by another way ( setup.name  value ) but no parameters setting by .expression seems to work.

Does anyone have the same problem?

 

mvh

Daniele

7 REPLIES 7
Message 2 of 8
kandennti
in reply to: danieleR9DDN

Hi @danieleR9DDN .

 

I tried the sample script you linked to and it worked fine.
(Win10  Ver2.0.12392)

Message 3 of 8
danieleR9DDN
in reply to: danieleR9DDN

Are you sure? Does it changes the name of the setup? If I try does not changes the name of the setup and also cannot change the tolerance or generate it if I've more than 1 setup.

Is also annoying that no error message appears if I launch it... simply it stops somewhere and do not say anything.

Message 4 of 8
kandennti
in reply to: danieleR9DDN

@danieleR9DDN .

 

The "programNameParam.expression" is here.

1.png

 

I dumped the Setup.parameters.

import adsk.core, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        doc = app.activeDocument
        products = doc.products
        cam = adsk.cam.CAM.cast(products.itemByProductType("CAMProductType"))

        setups = cam.setups
        
        setup: adsk.cam.Setup = setups.item(0)
        prm: adsk.cam.CAMParameter
        for prm in setup.parameters:
            print(f'{prm.name}:{prm.expression}')

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

I could not find any parameters related to the name of Setup.


I think the only way is to use setup.name.

 

Message 5 of 8
danieleR9DDN
in reply to: kandennti

ops... my faults I guess.... 

 

so now I need to figure out why my try to set other parameters does not work.

 

P.S.

Do you have any suggestion about how to debug a python script? My knowledge of Python is low and I really don´t know either where to read the print output from your last script.

 

Daniele

Message 6 of 8
kandennti
in reply to: danieleR9DDN

@danieleR9DDN .

 

CAM parameter names are displayed by moving the mouse cursor over the desired item with the Shift key held down to display the tooltip.

1.png

 

The API can only be used to set numerical values, etc., and it should not be possible to specify shapes, etc., at this time.

Message 7 of 8
danieleR9DDN
in reply to: kandennti

Thank you

 

I still have problems with some parameters that does not want to work like the job_stockMode. Any idea?

 

 

import adsk.core, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        doc = app.activeDocument
        products = doc.products
        
        # Get the CAM product
        cam = adsk.cam.CAM.cast(products.itemByProductType("CAMProductType"))

        # List of all setups
        setups = cam.setups
        
        for setup in setups:
            # Change the program name of each setup to 1234
            #programType = setup.parameters.itemByName('job_type')
            #programType.expression = "milling"
            programStockMode = setup.parameters.itemByName('job_stockMode')
            programStockMode.expression = "default"

            progModels=setup.models
            progComp=progModels.item(0).parentComponent

            compName=progComp.name
            setup.name = str(compName)

            programOffSidParam = setup.parameters.itemByName('job_stockOffsetSides')
            if compName.startsWith("T_"):
                programOffSidParam.expression = "2mm"
            else:
                programOffSidParam.expression = "3mm"

            programOffTopParam = setup.parameters.itemByName('job_stockOffsetTop')
            programOffTopParam.expression = "0mm"
            
            
            #for operation in setup.operations:
            #    # Change tolerance in all operations
            #    toleranceParam = operation.parameters.itemByName('tolerance')
            #    toleranceParam.expression = "0.1mm"
        
        # Generate all toolpaths, skipping any that are already valid
        cam.generateAllToolpaths(True)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Message 8 of 8
danieleR9DDN
in reply to: danieleR9DDN

OK, I learned how to use debug with Fusion360 and I was able to understand why.

 

The expressions must be quoted if are string, in this case the value mustn't be "default" but "'default'".

 

Thank you for your patience.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report