Maya 2020 fundamentals - modelling the real world
Get halfway through a model and find it's an unworkable mess? Can't add edge loops where you need them? Can't subdivide a mesh properly? If any of this sounds familiar check this course out.
# 1 11-07-2007 , 01:06 PM
faraj's Avatar
Registered User
Join Date: Dec 2006
Posts: 4

i have problem with this code...

string $selections[] = `ls -sl`;
for ($selection in $selections)
{
addAttr -ln vcoord -at double -min 0 -max 1 $selection;
setAttr -e -keyable true ($selection + ".vcoord");
}

when i try to execute i got this Message:

// Error: setAttr -e -keyable true ($selection + ".vcoord"); //
// Error: Illegal operation "+" on data of type string[]. //

# 2 12-07-2007 , 12:06 PM
kbrown's Avatar
Moderator
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Probably because the data type of your $selection variable is not defined. Try this:
Code:
string $selections[] = `ls -sl`;
string $selection;

for ($selection in $selections)
{
	addAttr -ln vcoord -at double -min 0 -max 1 $selection;
	setAttr -e -keyable true ($selection + ".vcoord");
}


Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
# 3 13-07-2007 , 01:36 AM
BadG3r's Avatar
Subscriber
Join Date: Jan 2007
Location: Frankfurt
Posts: 216
kbrown, in this case this isn't necessary.

faraj copy paste it from your post. it works for me.
and just by looking at the code it looks fine and like stated before it works sweet.

# 4 13-07-2007 , 11:01 PM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
actually kbrown is right from the point of view that it's ALWAYS a good idea to declare variables with a type. It saves any ambiguity and means that maya can't get it's knickers in a twist (more than it always does!)

You can also get errors with commands like match and substitute if you dont declare variables explicitly as strings.

The code looks fine to me though. You may of had an old variable called selection already declared as a string array and that's why it was bitching.

user added image
Alan


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 5 15-07-2007 , 06:16 AM
kbrown's Avatar
Moderator
Join Date: Sep 2002
Location: London, UK
Posts: 3,198

Originally posted by Alan
The code looks fine to me though. You may of had an old variable called selection already declared as a string array and that's why it was bitching.

Wise words my friend. This is why I always put everything inside an extra pair of curly brackets when noodling around in the script editor. This way you avoid declaring a bunch of global variables that can do all kinds of nasty things...


Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads