<< 01 02 03 04 05 06 07 08 09 10 >>
Tuesday, 21 August 2012
Rename Script
Little renaming script for iterating over a list of objects and renaming each item:
## place selection into variable 'sel':
sel = cmds.ls(selection= True)
## create a for loop and iteratate over the list:
for i in range(0,24):
##Use the rename command to rename the objects
cmds.rename(sel[i], sel[i][:3] + '%s' %(i))
print sel
Quick not on this one - the for loop uses 'range(0,24)' - this was me being a bit lazy, to make the script more dynamic I could have used the 'len()' function to set the for loop parameters, so it would have read:
for i in range (0,len(sel)):
blah blah etc
I then used string formatting to place the value of i at the end of the name
In the process I got nice and stuck on pretty noob style, schoolboy errors:
I first set up the for loop wrong:
for i in sel:
cmds.rename()
This set the value of i to the content of sel[] rather than its integer position - got errors like 'expecting type int got unicode'.
I also toyed with setting up an extra counter - declaring variable x as 0 outside the scope of the loop and then iterating inside the loop, but that meant x had a value of 1 and....you get the jist - bad idea and the wrong way of going about it
## place selection into variable 'sel':
sel = cmds.ls(selection= True)
## create a for loop and iteratate over the list:
for i in range(0,24):
##Use the rename command to rename the objects
cmds.rename(sel[i], sel[i][:3] + '%s' %(i))
print sel
Quick not on this one - the for loop uses 'range(0,24)' - this was me being a bit lazy, to make the script more dynamic I could have used the 'len()' function to set the for loop parameters, so it would have read:
for i in range (0,len(sel)):
blah blah etc
I then used string formatting to place the value of i at the end of the name
In the process I got nice and stuck on pretty noob style, schoolboy errors:
I first set up the for loop wrong:
for i in sel:
cmds.rename()
This set the value of i to the content of sel[] rather than its integer position - got errors like 'expecting type int got unicode'.
I also toyed with setting up an extra counter - declaring variable x as 0 outside the scope of the loop and then iterating inside the loop, but that meant x had a value of 1 and....you get the jist - bad idea and the wrong way of going about it
<< 01 02 03 04 05 06 07 08 09 10 >>
3d math home
Maths plays an integral role and is central to what lies beneath the hood in any computer program and is especially poignant in 3d. My previous experience with numbers goes about as far as GCSE, having decided to spare myself the mental anguish of enrolling at A-Level.
The reality is, you can get by in Maya with a fundamental understanding of Math, that is why programs exist; clever software boffins work hard to deliver scripts and tools long before anyone even knew they needed them. But as we know there is slightly more to Maya than just opening it up, hitting a few buttons in the interface and calling rendering it out.
Any character TD will tell you, being able to spot and isolate mathematical relationships and express them in the programming terms is paramount. Maya comes pre-packed with numerous input methods such as the expression editor, mel/python/c++ scripting, utility nodes and the connection editor, so you can be very explicit in what you want it to do.
Once I started coming up against more complex problems that couldn’t be solved with my limited knowledge, I decided it was time to brush up on my math skills (I could put it off no longer!). Don’t get me wrong, I am no Archimedes, but learning just a few basic algebraic laws has given me the confidence to solve and implement pretty basic equations that has helped me out no end.
I would encourage anyone wanting to learn a bit of 3d to take the time and do the math; it’s always a distinct advantage to know what’s going on beneath the hood when things invariably go wrong. The next pages I have put together are what I think is pertinent to 3d (the scope of the subject can leave you feeling a bit like your waving a stick in an empty field!). There is a lot of information to digest, so for me, these pages act as a revision aid in the hope that one day it will all sink in.
Please, as always feel free to leave any comments/suggestions or add to what I have missed!
The reality is, you can get by in Maya with a fundamental understanding of Math, that is why programs exist; clever software boffins work hard to deliver scripts and tools long before anyone even knew they needed them. But as we know there is slightly more to Maya than just opening it up, hitting a few buttons in the interface and calling rendering it out.
Any character TD will tell you, being able to spot and isolate mathematical relationships and express them in the programming terms is paramount. Maya comes pre-packed with numerous input methods such as the expression editor, mel/python/c++ scripting, utility nodes and the connection editor, so you can be very explicit in what you want it to do.
Once I started coming up against more complex problems that couldn’t be solved with my limited knowledge, I decided it was time to brush up on my math skills (I could put it off no longer!). Don’t get me wrong, I am no Archimedes, but learning just a few basic algebraic laws has given me the confidence to solve and implement pretty basic equations that has helped me out no end.
I would encourage anyone wanting to learn a bit of 3d to take the time and do the math; it’s always a distinct advantage to know what’s going on beneath the hood when things invariably go wrong. The next pages I have put together are what I think is pertinent to 3d (the scope of the subject can leave you feeling a bit like your waving a stick in an empty field!). There is a lot of information to digest, so for me, these pages act as a revision aid in the hope that one day it will all sink in.
Please, as always feel free to leave any comments/suggestions or add to what I have missed!
Subscribe to:
Posts (Atom)