Surface Normal of BrepFace

Surface Normal of BrepFace

ebunn3
Advocate Advocate
860 Views
2 Replies
Message 1 of 3

Surface Normal of BrepFace

ebunn3
Advocate
Advocate

Is there a way to determine the surface normal of a selected face using the API?

 

For example (see screenshot below):

 

  • I want to determine which direction the surface is facing. 
  • I believe the surface normal would tell me this?  But I am not sure.  

 

Any help would be greatly appreciated.

 

Eric

 

ebunn3_0-1628856420587.png

 

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

kandennti
Mentor
Mentor
Accepted solution

Hi @ebunn3 .

 

The normal direction of a surface can be obtained by using the SurfaceEvaluator object.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-31dad9b2-ee1d-4216-8100-09ea44f9967a 

 

This sample creates a sketch line in the normal direction when you click on the surface of the body.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core


def run(context):
    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

        msg: str = 'Click Face /ESC - Cancel'
        selFiltter: str = 'Faces'
        skt: adsk.fusion.Sketch = None

        while True:
            # select face
            sel: adsk.core.Selection = selectEnt(msg, selFiltter)
            if not sel:
                break

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

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

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

            # target point
            target: adsk.core.Point3D = click.copy()
            target.translateBy(normal)

            # sketch
            if not skt:
                skt = root.sketches.add(root.xYConstructionPlane)
                skt.name = 'Normal'

            # create Normal Line
            skt.sketchCurves.sketchLines.addByTwoPoints(click, target)

        if skt:
            skt.deleteMe()

    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

1.pngHere we have used the getNormalAtPoint method.

 

Note that "BRepFace.evaluator" and "BRepFace.geometr.evaluator" are not strictly the same.

 

Message 3 of 3

ebunn3
Advocate
Advocate

@kandennti 

 

Thank you so much.  This does exactly what I need.

 

Eric