Tutorial: How To Make Autodesk Maya Automatically Execute a Script When an Attribute Changes with scriptJob and scriptNode.

gravatar
By joel
 · 
January 15, 2020
 · 
1 min read
Featured Image

Making Maya automatically execute a script when an attribute changes is not as straightforward as it would seem. As someone new to Python, getting a scriptJob to work when referenced is confusing. It took me quite a bit of digging to get things to work, so I figured I'd share my finding to make it easier on the next person.

(more…)
Tagged: #Python · Attribute · attributeChanged · BLP · maya · Maya Python · MEL · referencing · Rigging · scripting · scriptJob · scriptNode
Comments
Stathis Nikou
Hi Joel,
I have a question.
I have a function inside your script Node that is been triggered when you change values on rotation X of a controller. I am putting keys on this attribute, until now everything is working perfect. If i go frame by frame i can see my animation, but when I scrub in the timeline or when I hit play nothing happens.
Any ideas?
Dan Marks
Hi Joel,
This is very cool, and super similar to something I am trying to solve.
I am curious though. When I look at your code in the Expression Editor in your Maya file, I only see the code from inside the quotes. How are you actually setting it all up? Sorry if that’s a stupid question.
Dan
That is exactly what I found most confusing. The code in the expression editor is just the code that, when executed, creates a scriptJob for the attribute dynamically. Meaning if you run the expression directly, it won’t do anything. The hidden scriptJob is what does the action. The attribute scriptJob is the thing doing the work, but you can’t view it anywhere, it’s completely hidden, which I think is dumb. And another tricky part is that if there is an error in the scriptJob, you have to manually delete it with code because it isn’t accessible anywhere. Took me like a day to figure out the flow of all that.

Leave a replyReply to