0
$\begingroup$

With a face selected, how do I get the transform orientation of the face / gizmo(normal) by script, and then be able apply it to an object(after moving another object to selection)?

enter image description here

tried the following code but getting weird result:

import bpy

#bpy.ops.mesh.separate(type='LOOSE')


import bmesh
import mathutils

# Get the active mesh (assumes starting in edit mode)
obj = bpy.context.edit_object
me = obj.data
coneradius=1     # Im not sure how you plan to scale the cone.
Up=mathutils.Vector((0,0,-1))

# Get a BMesh representation
bm = bmesh.from_edit_mesh(me)
selected_faces=[face for face in bm.faces if face.select]
if len(selected_faces)>0:
    norm=selected_faces[0].normal
    my_location=selected_faces[0].calc_center_median()
    # convert this to a rotation quaternion    
    Qrot=norm.rotation_difference(Up)

print(Qrot)

#an object called Cone is in the scene
cone=bpy.context.view_layer.objects["Cone"]
print(cone.rotation_quaternion)
cone.rotation_mode='QUATERNION'

cone.rotation_quaternion =Qrot
```
$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.