PDA

View Full Version : Selection command


nottoshabi
03-20-2008, 05:54 AM
I'm trying to create a button that creates to nulls and a nurbsCircle that have the same name as the selected object. The button and window is not a problem I'm having a problem with selection command. This is what I have:


string $select[] = `ls -sl`;


string $group1 = $select[0] + "_GRP";
string $circle = $select[0] + "_Ctrl";
string $group2 = $select[0] + "_ConstGrp";


CreateEmptyGroup -n $group1;
CreateNURBSCircle -n $circle;
CreateEmptyGroup -n $group2;


parent $circle $group1;

parent $circle $group2;



I get an error that says:

// Error: No object matches name: nurbsSphere1_Ctrl //

And it names nothing. What am I doing wrong?

strarup
03-20-2008, 09:32 AM
Hi Mike,

e.g. try this...

proc makeDaGrpsAndControls()
{
string $select[] = `ls -sl -l`;
string $group1 = ($select[0] + "_GRP");
string $circle = ($select[0] + "_Ctrl");
string $group2 = ($select[0] + "_ConstGrp");

group -em -n $group1;
circle -n $circle;
group -em -n $group2;

parent $circle $group1;
parent $circle $group2;
}
makeDaGrpsAndControls;

one of the problems is that CreateNURBSCircle calls the nurbsCircle draw tool thingie...
and which therefore "jumps" out of the thingie without creating a circle...
just use the circle command instead... if you want the circle to have a specific location...
radius, and direction... just add some more "flags" beside the name flag to the circle command...
instead of using CreateEmptyGroup just use the group command...

both CreateEmptyGroup and CreateNURBSCircle are command/procs/functions under default runtime commands
as I recall... based on clicking in a window or using the tools... the basic core commands in this case is
the group command and circle command... :)

btw. haven't touch the parent command... since I'm not sure what you exactly want ot have parented under what...
however in this case you first parent the circle to group1...
and in the next line you move from group1 to group2... leaving group1 empty...

hope that helps a little... :)

kind regards

Strarup

nottoshabi
03-20-2008, 06:31 PM
Thanks Strarup. On the parent comand I want Group1 to be the parent of Circle and Group2 to be child of Circle. Kind of like this.

Group1
Circle
Group2

strarup
03-20-2008, 08:08 PM
Hi Mike,

you're welcome... :)

regarding the parent thingie then just change it to...

parent $circle $group1;
parent $group2 $circle; //<--- this line


kind regards

Strarup

nottoshabi
03-20-2008, 08:38 PM
Thanks. I will give that a try.

nottoshabi
03-23-2008, 12:48 AM
Alex I played around with it. I got it to work I also added a point and orinet constraint so that it takes the world position. Now my question is what do I have to do to select multiple objects at once and not one by one. I'm runing this
proc makeDaGrpsAndControls()
{
string $select[] = `ls -sl -l`;
string $group1 = ($select[0] + "_GRP");
string $circle = ($select[0] + "_Ctrl");
string $group2 = ($select[0] + "_ConstGrp");


// Create Control groups.
group -em -n $group1;
circle -n $circle;
group -em -n $group2;

parent $circle $group2 $group1;

pointConstraint $select[0] $group1;
orientConstraint $select[0] $group1;
pointConstraint -e -rm $select[0] $group1;
orientConstraint -e -rm $select[0] $group1;
select $group1;
FreezeTransformations;

}
makeDaGrpsAndControls;

wima
03-23-2008, 02:45 AM
You want to loop through your selections.
I´m not at maya now and I´m not a Mel master but I think something like this might work.


proc makeDaGrpsAndControls()
{
string $select[] = `ls -sl -l`;

for ($each in $select)
string $group1 = ($each + "_GRP");
string $circle = ($each + "_Ctrl");
string $group2 = ($each + "_ConstGrp");

group -em -n $group1;
circle -n $circle;
group -em -n $group2;

parent $circle $group2 $group1;

pointConstraint $each $group1;
orientConstraint $each $group1;
pointConstraint -e -rm $each $group1;
orientConstraint -e -rm $each $group1;
select $group1;
FreezeTransformations;

}
makeDaGrpsAndControls;

strarup
03-23-2008, 11:09 AM
Hi Mike,

it is pretty much as Martin's example... where you just put the code into a loop...
you can either use the way as Martin used... (just need a {} in that loop example)...

for($each in $select)
{
//the code + the current object worked on is called $each...
}

or

for($i=0;$i<size($select);$i++)
{
//the code + the current object worked on is called $select[$i]...
}


I took the liberty to change Martin's code a bit to make it a bit shorther... and also instead of using your point and orientConstraint... used a parentConstraint which is a mixture of those 2... :)

kind regards

Alex


proc makeDaGrpsAndControls()
{
string $select[] = `ls -sl -l`;
for($each in $select)
{
string $group1 = `group -em -n ($each + "_GRP")`;
string $circle[] = `circle -n ($each + "_Ctrl")`;
string $group2 = `group -em -n ($each + "_ConstGrp")`;
parent $circle[0] $group2 $group1;
delete `parentConstraint $each $group1`;
makeIdentity -a 1 -t 1 -r 1 -s 1 $group1;
}
}
makeDaGrpsAndControls;

nottoshabi
03-24-2008, 04:28 PM
Ok thanks guys. Couple of questions:

What does the -em do?
And what does this do?
makeIdentity -a 1 -t 1 -r 1 -s 1 $group1;

unsmoothed
03-24-2008, 05:56 PM
hi,

Using -em with the group command defines it as being empty. makeIdentity is used to freeze an objects transforms.

-uN

nottoshabi
03-24-2008, 05:59 PM
hi,

Using -em with the group command defines it as being empty. makeIdentity is used to freeze an objects transforms.

-uN


Sweet. And the -a? The other ones I know, whats the -a?

strarup
03-24-2008, 06:26 PM
Hi Mike,

well the -em is a flag in the group command and is just the short version on the flag called "empty"...
so the command group -em = greating an empthy group
where as CreateEmptyGroup is a runtime command which at the end of the command order practically is calling the
core cmd which is group -em...

so CreateEmptyGroup -n $grpName = group -em -n $grpName... :)


there is also a parent flag in the group cmd... so basicly you could allready place the empty group2 under the circle at creation time...
and actually group1 doen't have to be empty at creation time you could allready throw in the circle aswell and just skip
the call to the parent command completly making the code one line shorther... :D

as shown in the new example a bit further down... have also put a couple of comments in it... :)

regarding makeIdentity it's the core command of the FreezeTransformations....
which also is a runtime command...

the flags in makeIdentity that is used in this example makeIdentity -a 1 -t 1 -r 1 -s 1 $group1; is...
-apply(-a) ( where 1 = true... if I didn't use that they moved to worldpos 0 0 0)
-translate(-t) (where 1 = true = freeze the translation)
-rotate(-r) (where 1 = true = freeze rotation)
-scale(-s) (where 1 = true = freeze scale... could have left this out since there is no scaling involved)

so basicly what this command does is saying... I want the object $group1 and the stuff under it remaining where it is positioned now...
and then have translation/rotation/scaling "frozen" to zero values (except scaling where the frozen value is 1)...

hope that helps a bit... :)

kind regards

Alex


proc makeDaGrpsAndControls()
{
string $select[] = `ls -sl -l`;
for($each in $select)
{
//creating the circle...
string $circle[] = `circle -n ($each + "_Ctrl")`;
//creating a group and put the circle in it...
string $group1 = `group -n ($each + "_GRP") $circle[0]`;
//creating an empthy group and parenting it under the circle...
string $group2 = `group -em -n ($each + "_ConstGrp") -p $circle[0]`;
//move the groups to the postion of the object and orient them...
//and afterwards delete the parentcontraints used for this operation...
delete `parentConstraint $each $group1`;
//freeze transformation/rotate/scale on the group thingie...
makeIdentity -a 1 -t 1 -r 1 -s 1 $group1;
}
}
makeDaGrpsAndControls;

strarup
03-24-2008, 06:31 PM
hehe... well can see unsmooted/Andy pretty much answered the question while I was writing this down... :)

well regarding the flag a = apply... which is a boolean... 1 or 0 value...

if I didn't put a 1 = true in the apply flag... all the groups moved back to where they where created... the apply managed to preserve the position they had gained after been moved by the parentConstraint to the Object is should be "paired" with... :)

kind regards

Alex

nottoshabi
03-24-2008, 07:06 PM
Yeah thanks Alex that really cleard things up. The one letter comands sometimes are not that easilly readable. And serching for them sometimes does not work. But yeah thanks its cristal clear now.

CGTalk Moderation
03-24-2008, 07:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.