python maya: 将组的中心对齐到指定位置
我这里有一个脚本,里面创建了一堆圆圈,并把它们放到一个组里。接着,我把这个组的中心点调整到它的边界框中。最后,我想把这个组的位置对齐到空间中的某个位置,首先需要获取定位器的位置。请问我该怎么解决这个问题?现在看起来对齐得不太正确。错误出现在代码的最后一行。谢谢大家的帮助。
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] )
1 个回答
0
我觉得你想要的是
cmds.xform(nodeGroup, cp=True, p=True)
去看看文档里关于 -p 这个选项的说明