how to catch failed chamfers

how to catch failed chamfers

sterlingcrispin
Explorer Explorer
509 Views
1 Reply
Message 1 of 2

how to catch failed chamfers

sterlingcrispin
Explorer
Explorer

I'm having chamfers fail quite often, I thought the returnvalue would be a good way to catch for this but when this line of code fails it doesn't return true or false it just hard fails and stops the program

 

chamfers.add(chamferInput)

 from the below 

 

            # Create the sweep.
            sweep = sweeps.add(sweepInput)
            
            #prepare chamfer
            faces = sweep.faces
            edges = adsk.core.ObjectCollection.create()

            for f in range(faces.count):
                for e in range(faces.item(f).edges.count):
                    edges.add(faces.item(f).edges.item(e))
                
            chamfers = rootComp.features.chamferFeatures
                    
            chamferInput = chamfers.createInput(edges,False)
            radiusMult = 0.5
            returnvalue = False
            while returnvalue is False and radiusMult > 0.1:
                returnvalue = chamferInput.setToEqualDistance(adsk.core.ValueInput.createByReal(radius*radiusMult))
                radiusMult *= 0.9
            if returnvalue is True:
                returnvalue = chamfers.add(chamferInput)
                if returnvalue is True:
                    chamfer = chamfers.add(chamferInput)

 

Is there another approach that would cause the program to continue and just not chamfer that Sweep object if it will fail?

0 Likes
510 Views
1 Reply
Reply (1)
Message 2 of 2

JeromeBriot
Mentor
Mentor

Use a try-except statment:

 

app = adsk.core.Application.get()
ui = app.userInterface

try:

    chamfers.add(chamferInput)

except:

    if ui:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes