creating a curve from points

141 views
Skip to first unread message

e955...@gmail.com

unread,
Mar 3, 2015, 8:50:20 PM3/3/15
to python_in...@googlegroups.com
Yo,

if you want to create a curve from a set of points that already exist. eg you want to create a curve from points on a mesh. Is this the cleanest way to do it?:

Pnt1=cmds.pointPosition('geo.vtx[330]')
Pnt2=cmds.pointPosition('geo.vtx[136]')
Pnt3=cmds.pointPosition('geo.vtx[58]')

cmds.curve(n='curve1', d=1, p=[Pnt1,Pnt2,Pnt3])

or is it possible to just enter the 'geo.vtx[330]' items into the curve command somehow? - basically im trying to shrink my script because i have a hell load of curves in my scene now.


thanks alot,
Sam

Kurian O.S

unread,
Mar 3, 2015, 8:57:42 PM3/3/15
to python_in...@googlegroups.com
What about this ?

vertexList = [330, 136, 58]
postList = []
for eachVer in vertexList:
    postList.append(cmds.pointPosition('pSphere1.vtx[%s]' % eachVer))
cmds.curve(n='curve1', d=1, p=postList)


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/91ebea63-0f77-4879-a3ed-4101ed6f2fb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--:: Kurian ::--

Chris Lesage

unread,
Mar 4, 2015, 3:44:54 AM3/4/15
to python_in...@googlegroups.com
Hi Sam,

How are you getting the list of vertices in the first place? If you are selecting points, see my 3rd example.

1. You can also use list comprehension to shorten this a bit more.

vertexList = [330, 136, 58]
postList = [cmds.pointPosition('pSphere1.vtx[%s]'%x) for x in vertexList]
cmds.curve(n='curve1', d=1, p=postList)


2. And I personally prefer .format() instead of %s string formatting. To me it is a bit easier to read.

vertexList = [330, 136, 58]
postList = [cmds.pointPosition('pSphere1.vtx[{0}]'.format(x)) for x in vertexList]
cmds.curve(n='curve1', d=1, p=postList)


3. If you are selecting your points to get them, you can do something like this:

selPoints = cmds.ls(sl=True, flatten=True) # flatten returns each vertex separately, instead of in ranges like pSphere1.vtx[127:130]
postList = [cmds.pointPosition(x) for x in selPoints]
cmds.curve(n='curve1', d=1, p=postList)

Chris Lesage

unread,
Mar 4, 2015, 3:49:29 AM3/4/15
to python_in...@googlegroups.com
Whoops, if you are working with selection, us os=True, instead of sl=True. Otherwise your point order won't necessarily be in order:

selPoints = cmds.ls(flatten=True, orderedSelection=True)
postList = [cmds.pointPosition(x) for x in selPoints]
cmds.curve(n='curve1', d=1, p=postList)

Cheers,
Chris

e955...@gmail.com

unread,
Mar 5, 2015, 6:34:00 PM3/5/15
to python_in...@googlegroups.com
wow thanks guys for all your help. Yep these look far neater than mine. Thanks muchly.

Sam

e955...@gmail.com

unread,
Mar 5, 2015, 7:54:07 PM3/5/15
to python_in...@googlegroups.com, e955...@gmail.com
Oh by the way Chris, as a side note,

if i then was going to use the positions stored through this list method, to move other items to this location with xform. how can, for example, element two in the list be isolated and then seperated further int x,y,z eg:

postList = [cmds.pointPosition('pSphere1.vtx[{0}]'.format(x)) for x in vertexList]

cmds.xform( 'object1',a=True, t=(postList[2][0],postList[2][1],postList[2][2])

i was trying to find information about extracting from lists. But couldnt find how to make it work in the context of another command.

thanks,
Sam
Reply all
Reply to author
Forward
0 new messages