Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Generation toolpath never ends in CAM

gregor.stupica
Contributor

Generation toolpath never ends in CAM

gregor.stupica
Contributor
Contributor

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.

 

Screenshot_2.jpg

 

#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

https://a360.co/2TZNEeB

 

0 Likes
Reply
349 Views
2 Replies
Replies (2)

kandennti
Mentor
Mentor

Hi @gregor.stupica .

 

The situation could not be reproduced with the linked data, but it could be reproduced with this data of “CAM Samples”.
1.png
However, because it cannot always be reproduced, the cause is unknown.
 
Since the part to stop is found to be this loop, why not comment it out and process it?
2.png
 
0 Likes

gregor.stupica
Contributor
Contributor

Seems that do the trick.

I think can be reported as bug.

 

thanks for look into it

 

0 Likes