title: python + maya: Rotate Y axis to be along vector
body: <p>How can I rotate the circle shape so it's y axis is along the supplied vector? The vector in this sample script is created using the two locators in the scene. The code is broken up into 3 sections. The first section just creates the test scene. The second part collects the vector. The third part is where I need help figuring out how to use the vector to adjust the rotation of the circle so it's Y axis is pointing along the collected vector. Thank you guys.</p>
  
  <pre><code>import maya.cmds as cmds
  import random
  import math
  
  cmds.select(all=True)   
  cmds.delete()
  
  #------------------------------TEST SCENE SETUP
  
  def genPos():
      x = random.uniform(-5,5)
      y = random.uniform(0,5)
      z = random.uniform(-5,5)
      return (x, y, z)
  
  a = cmds.spaceLocator(n='ctrl_00')
  b = cmds.spaceLocator(n='ctrl_00')
  
  cmds.xform(a, t=(genPos()) )
  cmds.xform(b, t=(genPos()) )
  
  cmds.createDisplayLayer(name="Ctrls")
  cmds.editDisplayLayerMembers('Ctrls', a, b)
  cmds.setAttr('Ctrls.color' ,14)
  
  cmds.select(clear=True)
  
  
  #-----------------------THE SCRIPT
  def normlizedVector(vecA,vecB,offset):
  
      nX = vecB[0] - vecA[0]
      nY = vecB[1] - vecA[1]
      nZ = vecB[2] - vecA[2]
  
      #vectorLength = distance vecA vecB
      # find the distance between the two supplied point3 values
      distX = pow( (vecA[0] - vecB[0] ) , 2.0 ) 
      distY = pow( (vecA[1] - vecB[1] ) , 2.0 ) 
      distZ = pow( (vecA[2] - vecB[2] ) , 2.0 )
  
      vecLength = math.sqrt(distX + distY + distZ)
  
      # the normalized vector is calculated by dividing the X, Y and Z coordinates by the length
      calcX = nX / vecLength
      calcY = nY / vecLength
      calcZ = nZ / vecLength
  
      # project point along vector, offset by a given value
      ptX = vecB[0] + (calcX * offset)
      ptY = vecB[1] + (calcY * offset)
      ptZ = vecB[2] + (calcZ * offset)
  
      return (ptX, ptY, ptZ)
  
  
  posA = cmds.xform(a,q=1,ws=1,rp=1)  
  posB = cmds.xform(b,q=1,ws=1,rp=1)  
  
  pt = normlizedVector(posA,posB,10)
  
  #--------MOVE AND ALIGN CIRCLE
  cir = cmds.circle( nr=(0, 0, 1), c=(0, 0, 0) )
  cmds.xform(cir, t=posB )
  </code></pre>