Friday, April 15, 2011

Python (Day 15)

Programming/Scripting. I haven't done this in a long time, I used to do PHP back in the day, but that was about 8-9 yrs ago. Oh how time flies. Today's task was originally suppose to be something else entirely. However as I began working on this, I decided that I need to make this today's task.

Lindsay has been trying to get me to use python for about a year now, and for some reason, I decided to give in today and just try it. I needed a script that would replace many pieces of geometry with one single piece. I will say that starting off I really had to break it down, and simplify. I wanted to do to much, to quickly, which really doesn't work. So Lindsay had to sort of work it out with me. I was really happy once I got it to work! So here's the script!
import maya.cmds as cmds
import random as rand
listOfShapes = cmds.ls("*Cube*",transforms=True)
duplicateSphere = cmds.ls("master",transforms=True)
for pli in listOfShapes:
#random variables
r_numb_r = [rand.randint(1,20),rand.randint(1,90),0]
r_numb_s = [rand.uniform(1,3),rand.uniform(1,4),rand.uniform(1,3)]

#constant vars
xstr = cmds.xform(pli,q=True,t=True,ws=True,a=True)
xform_rotate = cmds.xform(pli,q=True,ro=True,ws=True,r=True)

#get stuff done
new_obj_array = cmds.duplicate(duplicateSphere,n="NewShape_")
cmds.xform(new_obj_array,ro=r_numb_r,os=True,a=True)
cmds.xform(new_obj_array,t=xstr,ws=True,a=True)
print("Task Complete. Commence Celebration")
And there it is! I actually came home and started scripting a bit more, I may start playing around with gimp and finding out how that all works. I may also reinstall Ubuntu, and boot up some Linux!

No comments:

Post a Comment