Instancing a model


#1

Hi
I’m new to Python and I’m doing some experiments to create instances of an object duplicate a model, change the scale, change the texture and hopefully change the shape of the model. So far I’ve managed to get

from maya import cmds

#duplicate and scale model
cmds.select('pSphere1')
cmds.duplicate('pSphere1')
cmds.move(15, 0, 0)
cmds.scale(0.5, 0.5, 0.5)

import random

#randomly assign texture
textures = ['Phong1', 'Phong2', 'Phong3', 'Phone4']
cmds.select('pSphere2')
cmds.hyperShade( assign=textures[random.randint(0,3)])

All of the textures in the code have been created and can be seen in the Hypershade but when I run the script I get “# Error: No shader is selected to be assigned” I’ve been playing around with it for a while but I just can’t figure out what I’m missing.

Any help would be really appreciated.
Thanks.


#2

use cmd.sets() to assign shaders, not hyperShade cmd.
Requires no selection.

example:

cmds.sets(‘shadingGroupName’, forceElement=‘pSphere1’)