Compare and Edit after running script

Compare and Edit after running script

dames123
Advocate Advocate
2,335 Views
24 Replies
Message 1 of 25

Compare and Edit after running script

dames123
Advocate
Advocate

I have a script I run that creates NCPrograms. It's crude as I'm not a coder. There's one line that creates an error when using Compare and Edit after creating the NCPrograms. It does something to the flag to set the machine to 1.

 

prg.machine = setup.machine  # Set the machine to the same as the setup
 
I get the following error message in Compare and edit.
 
dames123_0-1724186371917.png

Is this a bug in Fusion or is there another way to write that line in the script?

 

 

#n360API Python script
import adsk.core, adsk.fusion, adsk.cam, traceback
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://url.us.m.mimecastprotect.com/s/R9VIC2kr1Nf6PQk3I9ku4o?domain=help.autodesk.com
        ncPrograms: cam.NCPrograms = camObj.ncPrograms
        for setup in camObj.setups:

            machineName = ""
            if setup.machine:
                # Access the name of the machine
                machineName = setup.machine.getName() if hasattr(setup.machine, 'getName') else "Unnamed Machine"

            # Log or display the machine name
            ui.messageBox(f"Setup: {setup.name}\nMachine: {machineName}")
            
            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 = False
            ncParameters.itemByName('nc_program_useMachineConfig').value.value = True
            ncParameters.itemByName('nc_program_filename').value.value = setup.parameters.itemByName('job_programName').value.value # Set the filename to the same as the setup
            ncParameters.itemByName('nc_program_comment').value.value = setup.parameters.itemByName('job_programComment').value.value

            ncIpt.operations = [setup]

            prg = ncPrograms.add(ncIpt)
            prg.machine = setup.machine  # Set the machine to the same as the setup
            
            
            

            # Duplicate the NCProgram
            duplicatedPrg = prg.duplicate()
            if duplicatedPrg:
                
                camObj.ncPrograms[-1].name = (setup.name + " SETUPSHEET")
                #ncParameters = duplicatedPrg.parameters
                
                # Set the post processor path only for the duplicated program
                post_processor_path = 'linked://' + 'setup-sheet-excel-2007.cps'
                ncParameters.itemByName('nc_program_post').value.value = post_processor_path
                
                
            else:
             ui.messageBox(f"Failed to duplicate NCProgram for setup: {setup.name}")
            

        ui.messageBox("Dont forget to set your tool numbers")

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

 

 

Any help is appreciated.

 

 

0 Likes
Accepted solutions (3)
2,336 Views
24 Replies
Replies (24)
Message 21 of 25

nubrandao
Collaborator
Collaborator

I will try thanks very much

0 Likes
Message 22 of 25

nubrandao
Collaborator
Collaborator

Failed:

Traceback (most recent call last):

File "C:/Users/bnuno/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/NewScript1/NewScript1.py", line 54, in run

ncParameters.itemByName('nc_program_post').value.value = post_processor_path

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users/bnuno/AppData/Local/Autodesk/webdeploy/pre-production/8f3280571a21b8ce3de79e366dcfbc59dbd1237e/Api/Python/packages\adsk\cam.py", line 15786, in _set_value

return _cam.ChoiceParameterValue__set_value(self, value)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

RuntimeError: 1 : Catastrophic error occurred in API function call

 

 

gives this error, what i have to change?

0 Likes
Message 23 of 25

Jorge_Jaramillo
Collaborator
Collaborator
Hi,

It seems that your are not using the last version I sent, because that sentence where you get the error is not in that latest version.
If you're using other version, it is very handy that you share your routine/function so we can analyze it and provide a feedback. Just the error message is not enough (I believe)

Regards,
Jorge Jaramillo
0 Likes
Message 24 of 25

nubrandao
Collaborator
Collaborator

tried the last version, it crashed fusion, hmm going to remove machine from setup, going to try

 

0 Likes
Message 25 of 25

nubrandao
Collaborator
Collaborator

It works now, I have to change to my current post Heidenhain 

 

Perfect

0 Likes