Generation toolpath never ends in CAM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have created simple script that goes trought all my cam setups and export g code to folder.
After last update its not working any more. ProgressDialog in picture is stuck in the middle and cannot generate code.
I noticed if I suppress 2d contour, the script can go trought and gcode is generated.
Im not sure if its API or CAM issue.
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback, os, time
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.activeDocument
products = doc.products
product = products.itemByProductType('CAMProductType')
if product == None:
ui.messageBox('There are no CAM operations in the active document. This script requires the active document to contain at least one CAM operation.',
'No CAM Operations Exist',
adsk.core.MessageBoxButtonTypes.OKButtonType,
adsk.core.MessageBoxIconTypes.CriticalIconType)
return
cam = adsk.cam.CAM.cast(product)
#postConfig = ('C:\\test\\posts\\mach.cps')
postConfig = ('C:\\test\\posts\\osai.cps')
dirname = 'c:\\test\\'
outputFolder = dirname
viewResult = False
units = adsk.cam.PostOutputUnitOptions.DocumentUnitsOutput
#ui.messageBox(postConfig)
#Generate toolpath
if not cam:
ui.messageBox('No CAM data exists in the active document.')
return
#Generate toolpath
if not cam:
ui.messageBox('No CAM data exists in the active document.')
return
future = cam.generateAllToolpaths(False)
numOps = future.numberOfOperations
# create and show the progress dialog while the toolpaths are being generated.
progress = ui.createProgressDialog()
progress.isCancelButtonShown = True
progress.show('Toolpath Generation Progress', 'Generating Toolpaths', 0, 10)
# Enter a loop to wait while the toolpaths are being generated and update
# the progress dialog.
while not future.isGenerationCompleted:
# since toolpaths are calculated in parallel, loop the progress bar while the toolpaths
# are being generated but none are yet complete.
n = 0
start = time.time()
while future.numberOfCompleted == 0:
if time.time() - start > .125: # increment the progess value every .125 seconds.
start = time.time()
n +=1
progress.progressValue = n
adsk.doEvents()
if n > 10:
n = 0
# The first toolpath has finished computing so now display better
# information in the progress dialog.
# set the progress bar value to the number of completed toolpaths
progress.progressValue = future.numberOfCompleted
# set the progress bar max to the number of operations to be completed.
progress.maximumValue = numOps
# set the message for the progress dialog to track the progress value and the total number of operations to be completed.
progress.message = 'Generating %v of %m' + ' Toolpaths'
adsk.doEvents()
progress.hide()
programName='testProg'
# create the postInput object
postInput = adsk.cam.PostProcessInput.create(programName, postConfig, outputFolder, units)
postInput.isOpenInEditor = viewResult
setups = cam.setups
i = 0
filename = str('('+programName+')'+ setups.item(i).name)
#ui.messageBox(setups.item(i).name+' '+str(setups.item(i).models.count))
postInput = adsk.cam.PostProcessInput.create(filename, postConfig, outputFolder, units)
setup = setups.item(i)
postInput.isOpenInEditor = viewResult
r = cam.postProcess(setup, postInput)
'''
if r==True:
ui.messageBox('Post processing is complete. The results have been written to:\n"' + os.path.join(outputFolder, programName) + '.nc"')
else:
ui.messageBox('Posting failed')
#ui.messageBox('file %s out %s ' % (filename,outputFolder) )
'''
#ui.messageBox('done')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
link to model