2
$\begingroup$

I need to be able to find the normal of a selected face (given that we are in edit mode), or be able to compare the position of the face to the origin of the object. I have no idea how to start either of these things because I'm new to blender python scripting. With any advice you already have my thanks.

$\endgroup$
  • $\begingroup$ I assume you need the face normal, not the vertex normals? Please also only ask one question at a time. Comparing the origin to the face position is something different. $\endgroup$ – aliasguru Aug 13 '16 at 10:13
  • $\begingroup$ @aliasguru, I know that it was two questions, but as I was searching for the answer for one, I didn't know whether or not it was possible. Sorry about that. $\endgroup$ – TheShadowblast123 Aug 13 '16 at 10:37
3
$\begingroup$

You'll need to :

import bpy

Then get the object you want :

obj = bpy.context.active_object #The active object
obj = bpy.data.objects['Cube'] #The object by its name

Then for the object information :

obj.location #Object position rotation, scale
obj.rotation
obj.scale

Object faces are in data.polygons :

p = obj.data.polygons[0]
p.select #Indicates if the face is selected
p.normal #The face normal
p.vertices #The vertices indexes

The vertices and their positions :

vIndex = p.vertices[0] #Index of the vertex from the face p
v=obj.data.vertices[vIndex] #The corresponding vertex object
v.co #Its coordinates

It can be a good way to learn how to navigate through the objects hierarchy using the Python console and CtrlSpace for auto completion and discover the object properties (in complement to the documentation) :

enter image description here

$\endgroup$
  • $\begingroup$ so question is the face normal something like a vector. Does it just have 3 float values? $\endgroup$ – TheShadowblast123 Aug 13 '16 at 10:35
  • $\begingroup$ @TheShadowblast123, the normal is a 3D vector yes $\endgroup$ – lemon Aug 13 '16 at 10:43
  • $\begingroup$ This doesn't answer the question at all, does it? The question was about accessing face normals. $\endgroup$ – foobarbecue Jul 24 '18 at 18:03
  • $\begingroup$ @foobarbecue, This answer is more giving advice about a way to learn how to access Blender data in Python, because the OP asked about normals but not only in the question. Though faces normals access is given in the line "p.normal". But if needed, feel free to provide another answer. $\endgroup$ – lemon Jul 25 '18 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.