- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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()))
Solved! Go to Solution.