That doesn't actually work at all for me. The second time through the loop
it creates a second instance with the same name as the first, then fails
with
# ValueError: More than one object matches name: [u'polySphere1_inst'] #
It works for me if I don't try to set the name in the instance command, and
let Maya name the object itself, then I rename the object on the last line
of the loop, like:
rename(instObject[0], '%s_inst' % (result[0]))
because the object has already been grouped with the others, Maya gives it
a unique name.
On Wednesday, 30 August 2017 14:14:52 UTC+10, jettam wrote:
>
> I am trying to get all 50 instances to go into the instanceGroup. But for
> some I am only getting one instance object in to the group. Could someone
> help me with this. Why is my script not nesting all 50 instance into the
> group?
>
> import maya.cmds as cmds
> import random
> random.seed (1234)
>
> result = cmds.ls(orderedSelection=True)
>
> instanceGroup = cmds.group(empty=True, name='Grp_Inst_%s' % (result[0]))
>
> for i in range(0,50):
>
> instObject = cmds.instance(result, name='%s_inst' % (result[0]))
> *cmds.parent(instObject, instanceGroup)*
> x=random.uniform(-10,10)
> y=random.uniform(0,20)
> z=random.uniform(-10,10)
> cmds.move(x,y,z,instObject)
>
> rotX=random.uniform(0,360)
> rotY=random.uniform(0,360)
> rotZ=random.uniform(0,360)
> cmds.rotate(rotX,rotY,rotX,instObject)
>
> uniformScale=random.uniform(.4,1.4)
> uniformScale=random.uniform(.4,1.4)
> uniformScale=random.uniform(.4,1.4)
> cmds.scale(uniformScale,uniformScale,uniformScale,instObject)
>
>
>
>
>
>
>
>
>
>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/c5b1d73b-6851-4775-823a-00e7bdc767f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.