Message 1 of 25
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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.
Solved! Go to Solution.