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: 

Surface Normal of BrepFace

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ebunn3
369 Views, 2 Replies

Surface Normal of BrepFace

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

 

2 REPLIES 2
Message 2 of 3
kandennti
in reply to: ebunn3

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
in reply to: kandennti

@kandennti 

 

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

 

Eric

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