Problems with draft features on cylindrical face.

Problems with draft features on cylindrical face.

ebunn3
Advocate Advocate
440 Views
2 Replies
Message 1 of 3

Problems with draft features on cylindrical face.

ebunn3
Advocate
Advocate

Hi,

 

The attached code will crash if I run it on any face that is connected to a cylindrical wall.  (see pics below)  The code works well on all other features.  Can someone explain why the createInput call on line 75 crashes when selecting a cylindrical face.

 

Thanks in advance for the help.

Eric

 

ebunn3_0-1629210752703.png

ebunn3_1-1629210773710.png

 

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)

                # 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)   
            elif dialogResult == adsk.core.DialogResults.DialogNo:
                break
            i += 1

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

 

0 Likes
441 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

I'm able to reproduce the problem and will make sure a bug gets filed.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 3

ebunn3
Advocate
Advocate

Brian

 

Is there somewhere that these issues are tracked so I can see when there is a fix for it?

 

Eric

0 Likes