简体   繁体   English

python maya:将组枢轴对齐到提供的位置

[英]python maya: Align group pivot to supplied position

What I have here is a script where I create a bundle of circles and place them into a group. 我这里是一个脚本,在其中我创建了一个圈子束并将其放入一组。 I then center the groups pivot to the bounding box. 然后,我将组的轴心居中到边界框。 Lastly I'm wanting to align the groups position to the location in space by first collecting the locators position. 最后,我想通过首先收集定位器的位置来将组的位置与空间中的位置对齐。 How can I fix this? 我怎样才能解决这个问题? Currently it doesn't seem to align properly. 目前,它似乎无法正确对齐。 The error occurs in the last line of the code. 错误发生在代码的最后一行。 Thank in advanced guys. 谢谢高级人员。

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] )

I think you want 我想你要

cmds.xform(nodeGroup, cp=True, p=True)

check the docs for the -p flag 检查文档中的-p标志

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM