[Maya] Space switching with position matching

Hi!

I’m currently working on an autorig, and trying to figure out one thing - is there a way to automate space switch position matching on Enum attribute change? For that a script needs to be executed on switch, and it should remember position that was before the switch and then restore it after the switch, as I understand it.

But I’m not sure how to achieve this and preferably in a sort of lightweight way. ScriptJob attached to attribute change will only run after the change, which is kind of useless in this case.

i have a script that generates this:


the only downside on the scriptjob is that its not able to evaluate in parallel.

Cool, thanks!

I’m going with matrix nodes instead of constraints though, so can’t just use your script. At least assuming it’s using constraints.

But I also think I worked it out since posting this thread, please correct me if I’m doing it wrong:

  • I have a scriptNode that has code to generate scriptJob when scene opens
  • scriptJob then watches a dummy switch attribute that’s not connected to anything
  • when that attribute changes scriptJob knows which other attribute it needs to change. So it remembers position of the object, changes the attribute and restores object position

Still need to figure out how to adjust it to only use 1 script job though.

Another thing I’ve ran into is this discussion: https://forums.autodesk.com/t5/maya-programming/attributechange-scriptjob-and-its-lying-ways-help/td-p/6217887

That says that Maya’s default scriptJob that looks for attr change actually fires off even during frame change, which involves additional overhead. I’m not sure if it’s still a case in latest Maya, but as I’m trying to optimize as much as I can (within reason) I opted to go with this option too. Interested in your opinion on this, or maybe you’ll just find it useful for your tool.