Enum execute a mel script


#1

So Im trying to create a button at the bottom of my custom attributes on a curve to reset some other custom atributes to 0

at the moment I have a enum at the bottom of the Channel Box with “Green” chanced to “Reset” (deleted blue, think i might need to add a second value, maybe “1” so that maya can pick up the change, and then once the script launches, switch the option back to “Reset”)

I have put my script commands in a script node and if I open the expression editor, filter by script node name, select the script node and hit test script, it works (well, does what i want it to)

I need help with if I select the reset value, it will execute the script


#2

Make sure your script node is set up as a function so you can call it from the script editor after you’ve hit "test:. Also make sure its set to run on file open/close so it’s sourced and callable once your file is open.

i.e. in mel it could be;

global proc PHello()
{
print ("\n\nHello… Testing\n\n");
}

Now once the file is opened you have a new mel command caleld PHello which can be run in the script editor.

To add this as a scriptJob simply set it up with the -attributeChange flag so in mel with a object called pSphere1 and a extra enum called Run;

scriptJob -attributeChange pSphere1.Run PHello;

The enum only needs 1 value, clicking on it will act as if it’s change.

If you now select the enum the mel script PHello is called and prints hello…testing, but if you close maya and re-open it and load the same scene, the script job isn’t saved.
To get past this, add it to the script node outside of the function so it’s called on file open.

i.e. your script node should now look like this;

global proc PHello()
{
print ("\n\nHello… Testing\n\n");
}
scriptJob -attributeChange pSphere1.Run PHello;


#3

I forgot to mention that if you add the extra attribute to a object with keyframes then it will call the script job when you press the play button, so add this control to its own separate control object that can’t be keyed.

Also, setting the hide on playback flag also causes the script to be called, but if you set this flag on the shape node instead, it seems to run fine.


#4

That seems workable. only thing I dont like is the fact that the script gets called the whole time. meaning if I have multiple of these scripts, it could slow the rig down.

The scriptnode does have a “execute on demand” attribute, but I dont know how to leverage that… how to demand from it basically.

would be nice if you could plug a condition node into the script node, so that when a condition is met, it will run script.