PDA

View Full Version : help with mel strings


landrews510
07-16-2007, 06:17 PM
I have a string of letters and say I want to know if the 5th letter in the string is equal to a. is there a way to do this.

I have tried using substring command but I get the following error, and haven't been able to find another way around the problem

string $tmp = "abbaabca";
string $letter = "a";

if ( substring $tmp 5 5 == $letter ) {
sphere -radius 5 -name "ball";
};
// Error: if ( substring $tmp 5 5 == $letter ) { //
// Error: Line 4.20: Invalid use of Maya object "substring". //
// Error: }; //
// Error: Line 6.1: Syntax error //

Derek Wolfe
07-16-2007, 07:28 PM
You left out the back-ticks around the substring command.

string $tmp = "abbaabca";

string $letter = "a";

substring $tmp 5 5;

if ( `substring $tmp 5 5` == $letter ) {

sphere -radius 5 -name "ball";

};

landrews510
07-17-2007, 10:57 PM
Derek, thanks so much, I'm new to mel and that one was giving me a hard time.

after your suggestion I looked to find out why I couldn't find it and the only reference I could find in the maya manual was.

Note
MEL does not support assigning string attributes to strings in statements like:
string $str = foo.str
Use this instead:
string $str = ‘getAttr foo.str‘;

so thanks again for the help

Derek Wolfe
07-18-2007, 07:22 PM
Glad to help.

If you search the docs for "backquotes eval" you can review some more info you might find interesting for the future.

CGTalk Moderation
07-18-2007, 07:22 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.