Created
April 13, 2019 03:58
-
-
Save Onefabis/797dbf07d9f01a1db1c9eb4134d5fb8b to your computer and use it in GitHub Desktop.
space objects evenly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as mc | |
import maya.api.OpenMaya as om2 | |
def spread(x,objType='spaceLocator'): | |
sel = mc.ls( sl=1 ) | |
if len(sel) != 2: | |
mc.warning('Please select two objects') | |
return | |
pos1 = mc.xform( sel[0], q=1, ws=1, t=1 ) | |
pos2 = mc.xform( sel[1], q=1, ws=1, t=1 ) | |
vec = om2.MVector( pos1 ) - om2.MVector( pos2 ) | |
part = vec.length()/(x+1) | |
mc.select(d=1) | |
objs = [] | |
for m in xrange(x): | |
pos = vec.normalize() * (m+1) * part | |
obj = eval( 'mc.' + objType + '()' ) | |
mc.xform( obj, ws=1, t=(pos2[0]+pos[0],pos2[1]+pos[1],pos2[2]+pos[2] ) ) | |
mc.select(d=1) | |
objs.append( obj ) | |
mc.select( objs, r=1 ) | |
spread(3, 'spaceLocator') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment