PDA

View Full Version : Do something and move on.


nottoshabi
03-27-2009, 02:18 AM
I'm trying to create a sphere for every obj I have in an array. Then constrain and name it as one of the selection in the array then move to the next selection in the array.

$sel[0] create sphere, name it as ($sel[0] + "Sph") point constrain it to the $sel[0]

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

for ($obj in $sel)
{
string $Ball = `polySphere -n ($sel[0] + "Sph")`;
pointConstraint $sel[0] $Ball;
}


So that if I have 3 locators named Loc1, Loc2, Loc3. I should have 3 spheres constrained to the locators and all they'r names should be Loc1Sph, Loc2Sph, Loc3Sph.

greatPumpkin
03-27-2009, 05:28 AM
I think you pretty much have it, only catch is that most create object type commands return a string array (the history node, and the actualy geometry)- you didn't post an error so I'm kind of guessing that's what's wrong?

This should work.. I think.. I also added the construction history off flag to polySphere since i'm assuming you don't need the history node-


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

for ($obj in $sel)
{
string $Ball[] = `polySphere -ch 0 -n ($sel[0] + "Sph")`;
pointConstraint $sel[0] $Ball[0];
}

fritz8th
03-27-2009, 02:51 PM
I think the problem your having is that you forgot to replace the $sel[0] variable with the $obj variable inside the for in loop. Right now your telling it to only make a sphere and constrain it to the first locator in the selection array;


Original Code:

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

for ($obj in $sel)
{
string $Ball[] = `polySphere -ch 0 -n ($sel[0] + "Sph")`;
pointConstraint $sel[0] $Ball[0];
}

New Code:

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

for ($obj in $sel)
{
string $Ball[] = `polySphere -ch 0 -n ($obj + "Sph")`;
pointConstraint $obj $Ball[0];
}


Hope that helps.

Dan

nottoshabi
03-27-2009, 08:56 PM
Yeah that did clear it up. I was messing around with it and tried on a bunch of different object and came across this.
string $selJnt[] = `joint -p 0 0 0 -n ($obj + "Jnt")`;
// Error: Cannot convert data of type string to type string[]. //


It runs the command but I can not use it in a variable how can I get around that?

fritz8th
03-27-2009, 09:13 PM
Your getting the error because your trying to store the joint information into the variable "$selJnt" which your saying is an array with the "[]" in front of it. To fix your error you just need to remove the "[]" . if you use the help docs when your writing your mel it will tell you the return type. Example for joint it says "Return Value: string"
Just for reference if your not already aware difference between string and string array:

//String
string $a = "Larry";

//String array,
//it becomes an array just because your storing more than one item
//inside the variable
string $b[] = {"Larry","Moe","Curly"};

string $selJnt[] = `joint -p 0 0 0 -n ($obj + "Jnt")`;
// Error: Cannot convert data of type string to type string[]. //

Dan.

CGTalk Moderation
03-27-2009, 09:13 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.