Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
In the following code, I can create and duplicate NCPrograms but I'm having trouble renaming the duplicate. It looks like the if statement doesn't do anything. No errors, just skips it. Any help would be appreciated.
#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 isinstance(duplicatedPrg, cam.NCProgram):
new_name = "SETUPSHEET"
duplicatedPrg.name = new_name
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()))
Solved! Go to Solution.