CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
To minimize the ads you see on this page create a CGTalk account and log in HERE
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 04-13-2013, 08:09 PM   #1
lazed
New Member
portfolio
Laszlo Mandi
bournemouth, United Kingdom
 
Join Date: Apr 2013
Posts: 7
Python Assign list values to an object's translateXYZ?

Hey guys, i have a list of WS coordinates that I collected from a plane's vertex positions.
Now lets say I also have a list of objects ( cubes for now), what i want to do is assign them cooridnates in my list to the cubes XYZ translate.

Could anyone point me to the right direction?

so far this is what i have:

vtxWorldPosition = []
for i in verts:
curPointPosition = cmds.xform( i, query=True, translation=True, worldSpace=True ) # [1.1269192869360154, 4.5408735275268555, 1.3387055339628269]
vtxWorldPosition.append( curPointPosition )

print vtxWorldPosition[1]
[-60.0, -2.6645352591003757e-14, 120.0]


cmds.polyCube()
cube = "pCube1"

cmds.setAttr(cube+".translate",vtxWorldPosition[0][0],vtxWorldPosition[0][1],vtxWorldPosition[0][2])

this places 1 cube to the location of the first coordinate in the list. now i guess i need to figure out how to make it use the lists in a for loop.


Any help would be much appreciated.
Thanks

Last edited by lazed : 04-13-2013 at 09:08 PM.
 
Old 04-14-2013, 12:37 AM   #2
Kobes
Veteran
portfolio
Jacob Santamaria
Melbourne, Australia
 
Join Date: Aug 2010
Posts: 70
Code:
import maya.cmds as cmds vtxWorldPosition = [] for i in verts: curPointPosition = cmds.xform( i, query=True, translation=True, worldSpace=True ) vtxWorldPosition.append(curPointPosition) for i in range(len(vtxWorldPosition)): #print vtxWorldPosition[i][0], vtxWorldPosition[i][1], vtxWorldPosition[i][2] cube = cmds.polyCube()[0] cmds.setAttr(cube+".translate", vtxWorldPosition[i][0], vtxWorldPosition[i][1], vtxWorldPosition[i][2], type="double3")


Hope this works and helps you out man. You might want to use the xform command to move the cubes also.

Cheers Jake
 
Old 04-14-2013, 01:33 AM   #3
lazed
New Member
portfolio
Laszlo Mandi
bournemouth, United Kingdom
 
Join Date: Apr 2013
Posts: 7
Thanks man. took me an hour and half to figure it out myself but got there at the end.
I still changed it abit around after seeing yours because mine wasnt perfect.
Many Thanks again.
Laz
 
Old 04-14-2013, 01:56 AM   #4
lazed
New Member
portfolio
Laszlo Mandi
bournemouth, United Kingdom
 
Join Date: Apr 2013
Posts: 7
i kinda ran into an error after trying to change it.

for i in range(len(vtxWorldPosition)):
#print vtxWorldPosition[i][0], vtxWorldPosition[i][1], vtxWorldPosition[i][2]
building = MakeRectengularTower(10, 10, 50, 6, 15, 20)[0]

## this is what builds me 10 buildings that i defined before, i added the [0] to the end of it because you had it after the polyCube so i thought it will work just fine. but i get this error:

# Error: 'NoneType' object is unsubscriptable
# Traceback (most recent call last):
# File "<maya console>", line 33, in <module>
# TypeError: 'NoneType' object is unsubscriptable #

# it creates my buildings but it doesent translate them to the vertex positons.

cmds.setAttr(building+".translate", vtxWorldPosition[i][0], vtxWorldPosition[i][1], vtxWorldPosition[i][2], type="double3")

any help would be much appreciated again.
Thanks for your time
 
Old 04-14-2013, 02:33 AM   #5
Kobes
Veteran
portfolio
Jacob Santamaria
Melbourne, Australia
 
Join Date: Aug 2010
Posts: 70
Yep I understand the problem your having. The reason I had the index on the back of the polycube command is because it returns a list of nodes.

Code:
import maya.cmds as cmds cube = cmds.polycube() print cube #[u'pCube5', u'polyCube5']


You can see here the cube variable is actually a unicode list of two nodes, the first being the actual transform node and the second being the polycube node. So the zero index at the end of the polycube command I had is only grabbing the transform node of the cube because that is the first in the list. The reason being that you wanted to edit the transformations of the cube not its actual properties.

So for your code I'm not sure how MakeRectengularTower() works but if you want to move it once you have created it you will want to return a transfrom node for the tower out of that function so that you can then position it. Right now it does not appear to be returning anything so that's the reason it says "# Error: 'NoneType' object is unsubscriptable".

Hope this clears it up and helps you out.

Cheers Jake
 
Old 04-14-2013, 02:41 PM   #6
lazed
New Member
portfolio
Laszlo Mandi
bournemouth, United Kingdom
 
Join Date: Apr 2013
Posts: 7
Thanks man it defo helped me, i managed to figure out how to return their values. Incase anyone else got the same problem, i just had to add this to the end of my function
buildinglist = [] # empty list
buildingslist.append(buildingname[0]) # adding new buildings to list

print ", ".join(buildingname) # thi is just a print so i know its building the towers
print "Completed, Loading rest of the structures..."
return buildingslist # returns the buildings after it built them

Many thanks for your help again.
Also just a quick question, do you know what the code is so i can see what my script is doing?
someone shown me before in class but i cant remember. i think its something to do with setting the viewport refresh time it was like one line of code
 
Old 04-14-2013, 02:41 PM   #7
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:26 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.