View Full Version : First Script Problem
Bpanting 08-14-2003, 05:08 PM This is my first time writing a script and I am having problems to get it to work. What I want it to do is add an attribute to a selected object and type in the the string collision_object name. Can anyone please tellme what I am doing wrong. Any other tips or suggestions would be cool also seeing as how I am just starting to get into this.
string $selected;
$selected = 'ls -sl';
ls -sl;
addAttr -ln NiData_ObjectString -dt "string";
setAttr -type "string" "collision_" + $selected;
|
|
I think you just have some bad sytanx.
// ls returns an array, so the varible you cast it to must be an array
string $selected[];
$selected = 'ls -sl';
// becasue the array could have any number of elements in it
// loop through it and add the attrs
for($i=0;$i<size($selected);$i++)
{
addAttr -ln NiData_ObjectString -dt "string" $selected[$i];
setAttr -type "string" ("collision_" + $selected[$i]) $selected[$i];
}
I haven't tested this, but it should get you pretty close.
--g
Bpanting
08-14-2003, 06:03 PM
Thanks for the help, but it is giving me a syntax error on
$selected = 'ls -sl';
Opps, didn't notice that it's the wrong tick mark.
You should use the back tick (the one by the 1 key) not the single quote.
$selected = `ls -sl`;
--g
Bpanting
08-14-2003, 06:44 PM
Cool that helps, Now it creates the attribute but it is not putting the "collision_object name" in the the field. Here is the error I am getting
// Error: line 10: No object matches name: collision_StreetLights_4 //
Sorry, never really looked that close at how you where setting the attr. The line should read:
setAttr -type "string" ($selected[$i]+".NiData_ObjectString") ("collision_" + $selected[$i]);
--g
Bpanting
08-15-2003, 02:55 PM
That did it thanks alot. Quick question though. You said before that the ls command returns an array, but when I looke up the command it said it returns a string. I am trying to understand how all this works, if you could shed some light on this for me that would be very cool. I guess I still have alot more reading to do on this MEL stuff, but it is very cool so far. Thanks again.
The docs says it returns string[], which is an array ( [] == array).
String is just the type of array, you can also have float[] and int[].
--g
Bpanting
08-15-2003, 06:13 PM
OK thanks, good to know. :thumbsup:
CGTalk Moderation
01-15-2006, 09:00 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.