Draft Features Bug

Draft Features Bug

ebunn3
Advocate Advocate
387 Views
2 Replies
Message 1 of 3

Draft Features Bug

ebunn3
Advocate
Advocate

Hi

 

I found a bug when creating an add-in for applying draft to a body.  Refer here:

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/problems-with-draft-features-on-cylindrica... 

 

Is there a way to prevent this exception dialog from appearing in favor of something more friendly.  Some type of error checking that would catch the error and display a message box with a message of my choosing?  I tried a try and except and that did not work.  I basically want to ignore the error.

 

Eric

ebunn3_0-1630599847418.png

 

 

0 Likes
Accepted solutions (1)
388 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

A try except statement will work.  The message box you're seeing is the result of the try failing and a message box is displayed in the except with the current error.  If it's not working, there must be a small problem in your code.

 

Here's a modified version of your program with a try except around the creation code and the display of a custom message. If you don't want a message at all you can remove the messageBox line.

 

import adsk.core, adsk.fusion, traceback

draft = 5

def surfNormal(app,ui,ent):
    # ui = adsk.core.UserInterface.cast(None)
    try:
        # app: adsk.fusion.Application = adsk.core.Application.get()
        # ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        face: adsk.fusion.BRepFace = ent.entity
        click: adsk.core.Point3D = ent.point

        # get SurfaceEvaluator
        eva: adsk.core.SurfaceEvaluator = face.evaluator

        # get Normal
        normal: adsk.core.Vector3D
        _, normal = eva.getNormalAtPoint(click)
        normal.normalize()
        return normal

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


def selectEnt(msg: str,filtterStr: str) -> adsk.core.Selection:
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        sel = ui.selectEntity(msg, filtterStr)
        return sel
    except:
        return None
        
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface


        # Get active design        
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        
        # Get root component in this design
        rootComp = design.rootComponent

        i=1
        while i<=10:
            dialogResult = ui.messageBox('Select the face(s) parallel to the base plane to draft from. Click "Yes" to add a face, "No to finish selections"','Draft Selection', adsk.core.MessageBoxButtonTypes.YesNoButtonType, adsk.core.MessageBoxIconTypes.QuestionIconType) 
            if dialogResult == adsk.core.DialogResults.DialogYes:            
                #select entity (ent = ui.selectEntity("Select a face to draft from.","Faces"))
                ent = selectEnt("Select a face to draft from.","Faces",)
                #get surface normal
                norm = surfNormal(app,ui,ent);print(int(norm.x),int(norm.y),int(norm.z))
                norm = str( int(norm.x) )  +  str( int(norm.y) )  +  str( int(norm.z)  )
                #get the face from the selection
                face1 = adsk.fusion.BRepFace.cast(ent.entity)

                try:
                    # Get all faces which connect to the first face
                    connectedFaces = [];
                    for edge in face1.edges:
                        for face in edge.faces:
                            if face1 != face:
                                connectedFaces.append(face)
                
                    # Create draft feature
                    drafts = rootComp.features.draftFeatures

                    draftFeatInput = drafts.createInput(connectedFaces, face1, True)

                    #set the draft direction based on the normal
                    # draftFeatInput.isDirectionFlipped = False
                    if norm == "001":
                        draftFeatInput.isDirectionFlipped = False
                    else:
                        draftFeatInput.isDirectionFlipped = True
                    #set the value of the angle
                    angle = adsk.core.ValueInput.createByString(str(int(draft)) + " deg")
                    angle2 = adsk.core.ValueInput.createByString(str(int(draft*-1)) + " deg")
                    #set for single angle
                    draftFeatInput.setTwoAngles(angle,angle2)
                    # draftFeatInput.setSingleAngle(False, angle)
                    #add the draft

                    drafts.add(draftFeatInput)   
                except:
                    ui.messageBox('Failed with my custom message.')
                    return
            elif dialogResult == adsk.core.DialogResults.DialogNo:
                break
            i += 1
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 3

ebunn3
Advocate
Advocate

Thank you Brian.  That will work for me.  I had tried just wrapping the try around the createInput function only which is where it would fail.  Thank you again.  This solves my problem until Autodesk comes up with a fix.

 

Eric

0 Likes