I currently have a random object generator script for MEL. I'm trying to convert it to Python. This is a homework assignment and I'm stuck at a particular section. I'm trying to add a random scale to each axis. I keep getting "can only concatenate list (not "str") to list #". Here's what I have so far:
#to use: my_rock_gen(1, poly_rock1)
#import python libraries
import maya.cmds as MC
import random
#define procedure with number of rocks and name
def my_rock_gen(number_of_rocks=0, rock_name="poly_rock1"):
#loop to generate rocks
for n in range(number_of_rocks):
#start with creating polygon object, basic cube
rock=MC.polyCube (name=rock_name)
#smooth it once
MC.polySmooth (rock, dv=2)
#give random scales
random_sx= random.uniform (.3, 3)
random_sy= random.uniform (.3, 3)
random_sz= random.uniform (.3, 3)
#set random values to scales
MC.setAttr ((rock + ".scaleX"), random_sx)"
I'm stuck at the last bit. In MEL here's what I have for the last 2 parts:
//set random scale range
float $random_sx = `rand .3 3`;
float $random_sy = `rand .3 3`;
float $random_sz = `rand .3 3`;
//set random values to scales
setAttr ($rock[0] + ".sx") $random_sx;
setAttr ($rock[0] + ".sx") $random_sy;
setAttr ($rock[0] + ".sx") $random_sz;
The $rock[0] is created with the beginning part of the script. I just can't figure out how the syntax should go for the setAttr part. Thanks for any help offered.