Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   syntax? (https://simplymaya.com/forum/showthread.php?t=14577)

Dann 04-12-2004 01:39 AM

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.

kbrown 04-12-2004 01:37 PM

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).

Dann 05-12-2004 07:06 PM

1 Attachment(s)
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.


All times are GMT. The time now is 04:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018