Activate Setup and Create NCprogram

Activate Setup and Create NCprogram

dames123
Advocate Advocate
407 Views
2 Replies
Message 1 of 3

Activate Setup and Create NCprogram

dames123
Advocate
Advocate

When I manually "activate" a setup. The stock shows and creating an NCProgram ports over the post from the machine and the program comment from the setup. It has to be activated with the stock showing though for it to work. In other words, it can't just be active, it has to be purposely clicked on to show stock.

 

see video: https://app.screencast.com/favqFh5yKg1jJ

 

In the following code, I can activate the setup, but it doesn't show stock and port the info over to the NCProgram. Is there a way to do this or am I going to have to code in the post and comments? I should be able to activate the setup properly, correct? That way I have one script that handles every machine instead of creating one script per machine with the post and everything else called out in the script. Am I on the right track or is this not possible?

 

Thanks.

 

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion
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

        # https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-995d634e-a8ef-4f2b-a826-1d32171f4998
        ncPrograms: cam.NCPrograms = camObj.ncPrograms
        for setup in camObj.setups:
            setup_index = 0
            setup_var = camObj.setups.item(setup_index)
            #Activate the setup
            returnValue = setup.activate()
            ncIpt: cam.NCProgramInput = ncPrograms.createInput()
            ncIpt.displayName = setup.name
            ncParameters = ncIpt.parameters
            ncParameters.itemByName('nc_program_filename').value.value = setup.name
            ncParameters.itemByName('nc_program_openInEditor').value.value = True
            ncIpt.operations = [setup]

            ncPrograms.add(ncIpt)

            

        ui.messageBox("Done")

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

 

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

kandennti
Mentor
Mentor

@dames123 -San.

 

I think CAM objects require more settings than CAD objects.
Many settings should need to be accessed through the parameters property.

 

If you have not read this section of the documentation, it would be good and helpful to read it all.

1.png

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-A08218F6-3885-4677-9CAD-7234BCEE85CC 

 

You may also find this sample code useful.

1.png

 

0 Likes
Message 3 of 3

dames123
Advocate
Advocate

@kandennti  thank you. I'll look into that.