Angle between 2 vectors using MEL in Python

Angle between 2 vectors using MEL in Python

# Node positions
pos0= cmds.xform(node0, q=1, ws=1, t=1);
pos1= cmds.xform(node1, q=1, ws=1, t=1);
pos2= cmds.xform(node2, q=1, ws=1, t=1);

# 2 Vectors. pos0-pos1 and pos0-pos2.
import maya.api.OpenMaya as om;
vec0= om.MVector(pos0);
vec1= om.MVector(pos1);
vec2= om.MVector(pos2);
vecA= vec0-vec1;
vecB= vec0-vec2;

# Radian and degree
import maya.mel as mm;
melVecFormatStrA= "<<"+str(vecA[0])+","+str(vecA[1])+","+str(vecA[2])+">>";
melVecFormatStrB= "<<"+str(vecB[0])+","+str(vecB[1])+","+str(vecB[2])+">>";
rad= mm.eval("angle "+melVecFormatStrA+" "+melVecFormatStrB);
deg= mm.eval("rad_to_deg("+str(rad)+")");

Comments

Popular posts from this blog

HIK: Getting current character and current source.