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 04-12-2004 , 01:39 AM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695

syntax?

Can anyone tell me what's wrong with this code? I know it does nothing for now, but I don't understand the error message Cannot cast data of type string to string[]

global proc editAttrPopup ()
{
$currentObj = `ls -sl`;
print($currentObj);
string $currentAttrMin = ($currentObj + ".up_Filter_Size");

window -menuBar true -maximizeButton false -title "Edit_Attribute" -iconName "editAttrPopupI" -w 200 -h 150 PopEditAttrB_w;
columnLayout;

rowColumnLayout -numberOfRows 2;

showWindow PopEditAttrB_w;

}

Thanks.

# 2 04-12-2004 , 01:37 PM
kbrown's Avatar
Moderator
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Can't check with maya right now but I can spot two things off top of my head...

The ls command returns always a string array. So you should do something like this:

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

Now let's say you're interested on the first object in the selection (index 0).

print($currentObj[0]);

The other thing is that in a script, you need to use the getAttr command to retrieve a value of an attribute. Like this:

string $currentAttrMin = getAttr($currentObj + ".up_Filter_Size");

You might want to also check the data type of the up_Filter_Size. Something tells me that it's not a string (although the above will propably work due to the automatic type conversion).


Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
# 3 05-12-2004 , 07:06 PM
Dann's Avatar
Registered User
Join Date: Feb 2003
Location: Los Angeles
Posts: 695
Thanks KB, I got that part working with your help, so now I'm back for more. I'm trying to link my script to an optionMenu, but can't get it right. I'm not very good at this yet, and the docs are prety crappy when it comes to helping with syntax. Thankfully there are people like you out there.

What it does is it builds a menu based on whatever user created attributes are on your object. Down the road, I'm going to try and read the min/max values of those attributes, and place those values in a field. Then there will be an edit button so I can change the min/max values of each attribute. I have a script that does that, so I'm just working on the interface.

What I am currently stuck on is when I run the script and change the menu selection, I can't get anything to happen. I tried the -command function on the menuItem, but it doesn't work when in optionMenu. I cannot figure out the syntax of the -cc function on the optionMenu, and while the docs claim it runs every time you change your selection, it does not.


global proc optMenu()
{
string $currentObj[] = `ls -sl`;

string $currentObjAttr[]= `listAttr -ud ($currentObj[0])`;
string $currentAttr = ($currentObj[0] +"."+ $currentObjAttr[0]);

int $counter = 0;

string $selected = $currentObjAttr[0];
// string $changeSelected = "print("+$selected+")";

window -menuBar true -maximizeButton false -title "Option Menu" -iconName "optMenu_I" -w 200 -h 150 optMenu_w;
columnLayout;

rowColumnLayout -numberOfRows 3;
optionMenu -label "Attributes" -cc "($selected = $currentObjAttr[$counter])";
while ($currentObjAttr[$counter] != "")
{
menuItem -label $currentObjAttr[$counter];
$counter +=1;
}
showWindow optMenu_w;
}


Thanks again for the help. Attached is a very simple Maya file you can use to test the script in you are so inclined.

Attached Files
File Type: zip optionmenu.zip (5.7 KB, 141 views)
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