Set post properties via API

Set post properties via API

Josh3GG88
Enthusiast Enthusiast
580 Views
4 Replies
Message 1 of 5

Set post properties via API

Josh3GG88
Enthusiast
Enthusiast

hi. i am struggling with setting a property to a value using API. I have managed to edit my post to show the post Properties in the operations tab, but when i try to give that a value, i am getting an error. 

0 Likes
Accepted solutions (1)
581 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor

Hi @Josh3GG88 -San.

 

I don't think anyone can answer this question because the text in the video is small and it is unclear what the property name is, and I don't know what the cps file is.

At the very least, you need the code and the cps file for the part where the properties are set.

 

The following sample enumerates the post property names and Value type names and values for the first NC program.

# 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

        ncPro: cam.NCProgram = camObj.ncPrograms[0]
        for postPrm in ncPro.postParameters:
            msg = f"{postPrm.name} : {postPrm.value.objectType}"
            try:
                msg += f" : {postPrm.value.value}"
            except:
                pass

            print(msg)

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

boopathi.sivakumar
Autodesk
Autodesk
Accepted solution

Hi @Josh3GG88 

Seems like you are trying to set the operation properties before even the operation is created. 

boopathisivakumar_0-1731310186965.png

Instead try after creating the operation

contour2dOp.parameters.itemByName('opProp_hoodPosition').expression = '2'

 

 


Boopathi Sivakumar
Senior Technology Consultant

Message 4 of 5

Josh3GG88
Enthusiast
Enthusiast

thanks for the point out. i can now adjust the value after i have created the operation. works very good

0 Likes
Message 5 of 5

Josh3GG88
Enthusiast
Enthusiast

Just thought I might ask. Is it a better practice to apply the operation property settings before or after creating the operation, or doesn't it matter?

0 Likes