python for loop with a mel function included

35 views
Skip to first unread message

mia...@hotmail.de

unread,
May 31, 2014, 1:26:32 AM5/31/14
to python_in...@googlegroups.com
hello
i want to do a planar mapping of four objects like this:


import maya.mel as mm
for i in range(12,15):
mm.eval("polyProjection -ch 1 -type Planar -ibd on -kir -md z pCube%s.f[4:6] pCube%s.f[8];" % i)


sadly this wont go...does anyone know how to do this ? I would be very thankful:)

Justin Israel

unread,
May 31, 2014, 3:08:44 AM5/31/14
to python_in...@googlegroups.com
I'm pretty sure the error you are seeing from this is that there are not enough format arguments for the string? It is because in your string you use %s two times but only provide one format argument. It would work if you modified it to:
mm.eval("polyProjection -ch 1 -type Planar -ibd on -kir  -md z  pCube%s.f[4:6] pCube%s.f[8];" % (i,i))
Also, you said you wanted to affect 4 objects, but if you do range(1,4), that will only produce [1,2,3]

I think you could also express this through the python commands module with:
import maya.cmds as cmds 

for i in xrange(1,5):
    obj = "pCube%d" % i
    objs = ["%s.f[4:6]" % obj, "%s.f[8]" % obj]
    cmds.polyProjection(objs, ch=True, type="Planar", ibd=True, kir=True, md="z")




--
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/9c32c4d2-af4e-4164-83e6-8a9820d33133%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages