PDA

View Full Version : Noob MEL question - event listener


mitchrichie
12-17-2009, 09:45 PM
I'm trying to make it so that as flipper1's rotate X reaches 360, flipper2 rotates 18 degrees. What am I doing wrong? Obviously the If-Then statement is only evaluated once, when you execute the script. How do I make it "listen" for when the rotation is 360, and then complete the IF-Then?

global proc MySliderMaker()

{ window -title "Slider Window" TestWindow3;
columnLayout;
attrFieldSliderGrp
-min 0
-max 720
-at "flipper1.rx";
showWindow TestWindow3;
}



MySliderMaker

float $b;
$b = getAttr("flipper1.rotateX");

if ($b == 360)
{
setAttr flipper2.rx 18;
}

dbsmith
12-18-2009, 12:08 AM
Perhaps you would consider an expression? Or a set driven key?
These are designed to run frame by frame.

Select Flipper2, open up the expression editor (under animation editors)

Throw something like this in.

if(Flipper1.rotateZ == 360){
Flipper2.rotateZ = 18;
}

EdtheHobbit
12-19-2009, 09:38 AM
So far as I have figured out, MEL does not have an event-listening system. Clever use of expressions and Expression nodes can let you achieve pretty much the same effect. For your specific example, a set-driven key would probably work better.

norbertnacu
12-20-2009, 03:23 AM
Hi There,
Are you talking about scriptJob?

Open your script editor and run this command:

global int $g_nn_attribChange;

string $ballObj = "ball";
string $attrib = "rx";

if( !`objExists $ballObj` )
{
sphere -n $ballObj;
}


Create/Remove a scriptJob

// Create scriptJob
nnCreateAttributeChange( false, $ballObj, $attrib );

// Delete scriptJob
nnCreateAttributeChange( true, "", "" );


// Command

proc nnCreateAttributeChange( int $mode, string $ballObj, string $attrib )
{
global int $g_nn_attribChange;

if( $mode )
{
if( $g_nn_attribChange )
{
if( `scriptJob -ex $g_nn_attribChange` )
{
scriptJob -k $g_nn_attribChange;
print( "Killing scriptJob #" + $g_nn_attribChange + "\n" );
}
}
$g_nn_attribChange = 0;
return;
}

if( !$g_nn_attribChange )
{
$g_nn_attribChange = `scriptJob -ac ($ballObj + "." + $attrib) ("nnCreateAttributeChange_cmd(\""+ $ballObj +"\", \""+ $attrib +"\")")`;
print( "Created scriptJob #" + $g_nn_attribChange + "\n" );
}
}
proc nnCreateAttributeChange_cmd( string $ballObj, string $attrib )
{
float $val = `getAttr( $ballObj + "." + $attrib )`;
if( $val >= 0 && $val <= 90 )
{
print( $attrib + " value is >= 0 and <= 90\n" );
}
else if( $val >= 91 && $val <= 180 )
{
print( $attrib + " value is >= 91 and <= 180\n" );
}
}


Thanks,
Norbert Nacu

CGTalk Moderation
12-20-2009, 03:23 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.