我在这里有一个脚本,我创建了一个圆圈并将它们放入一个组中。然后,我将组枢轴居中到边界框。最后,我想通过首先收集定位器位置来将组位置与空间中的位置对齐。我怎样才能解决这个问题?目前它似乎没有正确对齐。错误发生在代码的最后一行。感谢先进的人。
import maya.cmds as cmds
import random
cmds.file(new=True, f=True)
a = cmds.spaceLocator(n='pipeCtrl_00')
x = random.uniform(-10,10)
z = random.uniform(-10,10)
cmds.xform(a, t=(x,0,z) )
#select all the locators you want to make curves on
locList = cmds.ls(type='locator')
nodes = maya.cmds.listRelatives(locList, type='transform', parent=True)
sorted(nodes)
points = []
#get position points
for n in nodes:
pos = cmds.xform(n, q = True, ws = True, t = True)
points.append(pos)
# create 2D grid of circles
numRows = 4
numColumns = 4
#create empty group for nodes
nodeGroup = cmds.group(em=True, name='Pipe_group_00')
for r in range(0,numRows):
for c in range(0,numColumns):
# Create circle shape and transform it
node = cmds.circle(ch=True, o=True, nr=(0, 0, 1), c=(0, 0, 0), r=.5)
cmds.xform(node, t=(r*(.5*2), c*(.5*2), 0) )
# Parent node under the group node
cmds.parent(node[0], nodeGroup, relative=False)
# center pivot of group node
cmds.xform(nodeGroup, cp=True)
# align group to path
# ------------------------------------------------------------------
print points[0]
cmds.xform(nodeGroup, ws=True, t=points[0] )
答案 0 :(得分:0)
我想你想要
cmds.xform(nodeGroup, cp=True, p=True)
检查文档中的-p标志