简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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