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.
$\begingroup$
$\endgroup$
2
-
$\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$– aliasguruCommented Aug 13, 2016 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$– TheShadowblast123Commented Aug 13, 2016 at 10:37
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
4
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) :
-
$\begingroup$ so question is the face normal something like a vector. Does it just have 3 float values? $\endgroup$ Commented Aug 13, 2016 at 10:35
-
$\begingroup$ @TheShadowblast123, the normal is a 3D vector yes $\endgroup$– lemonCommented Aug 13, 2016 at 10:43
-
$\begingroup$ This doesn't answer the question at all, does it? The question was about accessing face normals. $\endgroup$ Commented Jul 24, 2018 at 18:03
-
2$\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$– lemonCommented Jul 25, 2018 at 5:37