Creation Names And Action

Hi,

I new in scripting and i try to do a little one but i can't find all the procedures :

I want to create a cube with precises subdivisions and modify the vertices to have soft edges wheni smooth.
easy to do in live but i want have a preset.
On of my problem is to name the input at the creation :

polyCube -n box; (and after i don't find the command to rename the input node)

//Result: box polyCube1// (i want : box polybox1)

My problem after is, i just copy the actions i did on the vertices to move them,
if i create the script, it works, but if i already have an object who have this name, the scipt is acting on this one and not on the new because of his name....

i don't find many help in the help

Thanks
Jaz

You are gonna to want to capture the name in an arry as well as name on creation.
For example:
string $mycube[] = polyCube -n box;
The results are a transform and shape node will populate the array.
Then move the verts use this format (I am using the move command on one vert for the example. xform is generally better to use):
move -r 1 0 0 ($mycube[0] + ".vtx[290]");

When a second instance of the script is ran the results will be "box1", which will be captured by the array and used for any other commands that follow that format.

Hope that helps,
-Brian
www.melJunky.com

thanks, i understand the way you deal with.

But i still have a problem with the input, i need to increase the subdivisions to 5
and the variable concerne the name, not the input name.

i don't find how to write the input name of this object :

string $mycube[] = polyCube -n box;

setAttr "polyCube1.subdivisionsWidth" 5;
setAttr "polyCube1.subdivisionsHeight" 5;
setAttr "polyCube1.subdivisionsDepth" 5;

like this it works, but if i creat an other box, the name will be polyCube2 and the subdivision will not work
i tryed this

setAttr ($mycube[0]+ ".subdivisionsWidth") 5;

but of course it doesn't work because it understand box (not the box input) and maybe i wrote it bad to
i think the better will be to give a name to the input like the string $mycube
how to select the input of the object i just create and use a name who will change on eatch creation objets ?

it is so easy to do it in live i have to change all my way to think of maya

thanks, Jaz

Yes offcourse because you use a hardcoded name. the next created box is named polyCube2

CODE
{ // pollution protection block
  $box=polyCube -n "box1" -sx 5 -sy 5 -sz 5;
  rename $shape[1] ("poly"+capitalizeString($box[0]));
}

I modified the naming convention a bit but yes i could remake it right but would be tacky this ones better if you make many boxes.

oops my initial script changesd shapename but it seems you wnated to rename the istoryy shape. Or have you missundertood teh returned names

Ps the dfault maya naming convention is more motivated than thi tough since polyCube refeers to the fact taht its a polyCube node, wich ispart of history but your free to confuse the person who happend to do history debugging as much as you wish

There is no need to change the name to change the input use the following:

string $mycube[] = polyCube -n box;
setAttr ($mycube[1] + ".subdivisionsWidth") 5;
setAttr ($mycube[1] + ".subdivisionsHeight") 5;
setAttr ($mycube[1] + ".subdivisionsDepth") 5;

The subdivisions can be change on creation also:
string $myCube[] = polyCube -w 1 -h 1 -d 1 -sx 4 -sy 4 -sz 4 -ax 0 1 0 -tx 1 -ch 1 -n "myCube";

If you want to affect the transform node used index 0, or index 1 for the input of the shape node. Don't try to rename the input since if you delete history on the node the input is deleted for example:
delete -ch $box[0];

Hope that helps,
-Brian
www.melJunky.com

allways add {} around conde snippets since not all users know of sope! and then whan they paste this into a shelf button they suddenly have a big chance of screwing something up down the line especialy when you use names like $mycube, because they become global if not protected by files own scope. So having 2 shelf buttons that use $myCube can eb a sure way of shootingoneself in the leg.

Thanks to all,

i started it so bad, now it works pretty well.

for moving the vertices i used this way to write :

move -r 0 0.19 0 ($box[0] + ".vtx[24:29]") ($box[0] + ".vtx[66:71]")........;

i don't if there is a simple methode but it works like i wanted
it is most your script than mine

if somebody else want to use it, here is with a little icon based on the original polycube :

boxedgescript.zip

Thanks again

PS: i have to learn so much for scripting...pffff