Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Generation toolpath never ends in CAM

2 REPLIES 2
Reply
Message 1 of 3
gregor.stupica
169 Views, 2 Replies

Generation toolpath never ends in CAM

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

 

2 REPLIES 2
Message 2 of 3
kandennti
in reply to: gregor.stupica

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
 
Message 3 of 3
gregor.stupica
in reply to: kandennti

Seems that do the trick.

I think can be reported as bug.

 

thanks for look into it

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report