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: 

Confused by normals retuned for simple box solid

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
tiktuk
244 Views, 2 Replies

Confused by normals retuned for simple box solid

I am trying to do something to each face of a body where I need to look at each normal.

 

When listing the normals for a simple box I am getting this from the below script:

 

 

 

Body1
 6 faces found for Body1.
 Normal: (x: 1.00, y: 0.00, z: 0.00)
 Normal: (x: 0.00, y: 0.00, z: 1.00)
 Normal: (x: 0.00, y: -1.00, z: 0.00)
 Normal: (x: -1.00, y: 0.00, z: 0.00)
 Normal: (x: 0.00, y: 0.00, z: 1.00)
 Normal: (x: 0.00, y: 1.00, z: 0.00)

 

 

 

 Why is (x: 0.00, y: 0.00, z: 1.00) repeated? I expected one of them to have a negative Z.

 

The script:

 

 

 

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

app = adsk.core.Application.get()

# Function to convert a vector to a string
def vector_to_str(v: adsk.core.Vector3D):
    '''
    Converts a vector to a string.
    '''
    return '(x: {0:.2f}, y: {1:.2f}, z: {2:.2f})'.format(v.x, v.y, v.z)

# Function to list the normals of the faces of a body
def list_normals(body: adsk.fusion.BRepBody):
    # Log the amount of faces.
    app.log(f'{body.faces.count} faces found for {body.name}.')

    for face in body.faces:
        _, normal = face.geometry.evaluator.getNormalAtPoint(face.pointOnFace)
        app.log(f'Normal: {vector_to_str(normal)}')


def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        body = ui.selectEntity('Pick a body', 'SolidBodies').entity
        app.log(body.name)
        list_normals(body)

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

 

 

 

2 REPLIES 2
Message 2 of 3
BrianEkins
in reply to: tiktuk

The bad normal is because you're using the geometry associated with the BRepFace instead of the face itself. The face's normal will always point "outside" of the solid, and the normal from the geometry should be considered arbitrary. Instead of getting the SurfaceEvaluator from the geometry, get it from the BRepFace. To do this, change your line 21 from this:

 

_, normal = face.geometry.evaluator.getNormalAtPoint(face.pointOnFace)

 

to this:

 

_, normal = face.evaluator.getNormalAtPoint(face.pointOnFace)

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3
tiktuk
in reply to: tiktuk

Thanks @BrianEkins , that makes all the difference 😄 !

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report