PDA

View Full Version : my script works like a ghost no effect on maya


ph0t0n1st
12-24-2007, 06:21 PM
hi everybody, i made a simple script to select things easier.
it does that; if there is an active selection it saves selection to an array and if there is no selected object when you run it it loads array database to active selection here my scipt i tried to do that expression but first time i heard that maya and mel hates me :D
i tried this expression but it gave syntax error can you help on this too
if( size($seldb)= 0 ) > this syntax is bad as maya says i tried different ways i tried to paranthesise the result like (size($seldb) ) but didnt work should i declare size($seldb) to a integeer variable to achieve that.


and here is my script running but doint nothing


string $seldb[];
if ( size($seldb) < 1 )
for($single in $seldb )
{
select -add $single;
}
else
$seldb = `ls -sl`;

ph0t0n1st
12-25-2007, 11:30 AM
i fixed algorithm little more but its still not workin :(
string $seldb[];
string $tempdb[] = `ls -sl`;
int $tempq = size($tempdb);
if ( $tempq = 0 ) //if there is no selection load saved selection//
{
for($slct in $seldb)
{ select -add $slct ; }

}

else //if there is a selection save it //
$seldb = `ls -sl`;


i tried like that but if else condition has weird problem can somebody help me?

thanks already :)

Gravedigger
12-25-2007, 01:02 PM
hey!
it seems that you need some training in mel. unfortunately the mel syntax is in several parts different to c++ or similar languages. in the maya documentation theres a chapter about mel and expression. you should again go over it and write down the strange things about mel which you need to keep in mind.

one of your mistakes is a very logic one:
if($a = 3)
this code sets $a to 3 and the return value is true so the if statement is executed. it doesen't matter what $a was set to before.
if($a == 3)
this is what you ment to do. the '==' operator is to compare to values and the '=' operator is to set values

another thing is that you can use the 'select' command with arrays. so theres no need for a for-in-loop.

hmm...this is all i see right now. change those things and please tell me whether all is clear now. hope i could help and have a nice day!

ph0t0n1st
12-25-2007, 05:17 PM
thank you Gravedigger; i know basic C but it seems i forgot it neither :D

i remember now. i forgot it and tried to remember but i coudnt remember i thought it was like that
= is for boolean tests
== for non boolean reults (example if(x=5) would return 1 cuz boolean logic. :D i think i mix things because of my teacher hehe. now i fix my scrript

string $seldb[];
string $tempdb[] = `ls -sl`

if( (size($tempdb) = 0) )
select $seldb;
else
$seldb = `ls -sl`; i hope it works when i try it in maya. at uni library there is no maya :sad:

Gravedigger
12-25-2007, 05:56 PM
i'm programming with different languages but mel has some very strange syntax rules where i still make mistakes sometimes.

i tried the script and it works fine. here it is:


string $seldb[];
string $tempdb[] = `ls -sl`;
if(size($tempdb)==0)
select $seldb[];
else
$seldb = $tempdb;


keep in mind that when you put this code in a procedure that you should define $seldb as a global variable else it is deleted after processing.
hope this helped!

r4inm4ker
12-26-2007, 01:36 AM
= is for boolean tests
== for non boolean reults (example if(x=5) would return 1 cuz boolean logic.


no. '=' is an assignment operator ,"==" is comparison operator, so '=' shouldn't be used for comparison. Some language, for example python, will not allow you to do "if(x=5)" in the conditional statement.


if( (size($tempdb) == 0) )


Try to correct this bad habit because sometimes it passes compiler test, and you will waste hours searching for this little bug.

ph0t0n1st
12-26-2007, 08:12 AM
thank you so much gravedigger and r4inm4ker i fixed it with your helps and wanna share that simple script with you maybe it helps you


it saves selection(vertex,face,object, shaders whatever selected) and if you press it again when you have nothing selected it brings saved selection back

global proc smartsel()
{
global string $seldb[];
string $tempdb[] = `ls -sl`;
int $querytemp ;
$querytemp = size($tempdb);
if ( $querytemp == 0 )
select $seldb;
else
$seldb = $tempdb;
}

CGTalk Moderation
12-26-2007, 08:12 AM
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.