How to create a mel condition attribute for the scriptjob command

Hi everyone,
this is my first post. (sorry for my english)
I’m starting to study mel and I’m trying to create my first “snap ik/fk” script.
I’m trying to trigger the script via attribute with the scriptjob command.

until now i wrote this:

proc snap_L_IkLeg_on_L_FkLeg()

int $val = getAttr "l_leg_global_ctrl.snap";

$l_foot_fk = xform -query -worldSpace -translation l_foot_fk;
xform -worldSpace -translation $l_foot_fk[0] $l_foot_fk[1] $l_foot_fk[2] l_foot_CTRL;


int $scriptJobNum = scriptJob -attributeChange "l_leg_global_ctrl.snap" "snap_L_IkLeg_on_L_FkLeg" ;

I would like the script to work only when “l_leg_global_ctrl.snap” is equal to 1 (or another enum value…)
and not only -attributeChange.
I understood that I have to use a condition to do this, but I can’t figure out how.
From the maya guide I didn’t understand much
I tried to search for any suggestions, but i didn’t found anything useful…

can anyone help me please?

I think what you are trying to do is similar to this. Perry Leijten’s dynamic parent script

I have followed his script to make IK FK switch in python with script job. i don’t know MEL very much.

it is doing the same thing creating a script job which works when enum attribute changes but for parent switching. take a look.

hi Dhrvin thank for reply, I had a look to the script and I noticed the use of the script job command,
but I was looking for a MEL help , for now I am not yet able to understand phyton :frowning:
thanks again for your reply

not sure if this work but try giving this script to Chat GPT say it to convert to MEL that might give you some idea.

I tried a lot to play with ChatGpt to help me with mel, but in my experience I see that with the basic and simple
things it works fine, but if you try to ask something little more complex, not always it answers correctly.
However maybe with the correct and complete script in phyton, maybe it can translate it in mel. I will try…
thanks for the suggestion I will let you know

it worked! wow! I didn’t think it would work,
without your suggestion I don’t believe I would have found the solution, thank you so much!

I’m kind of impressed by chatGPT’s ability here, with mel or python. I had it make one the other day to quickly display the length of a curve. Using a scipt job on an attribute change for the curves info, it would update an annotation for me.
It can really do well for simple tasks, and even for helping to structure larger proceedures/automations.