You would typically employ a scriptJob; which is the Maya way of providing arbitrary callbacks to supported events, such as selecting a node.
From the documentation, MEL
// Set up a job that runs for the life of the application.
// This job cannot be deleted with the "kill" command no matter what.
scriptJob -e "SelectionChanged" "print \"Annoying Message!\\n\"" -permanent;
Though scriptJob is often looked down upon and should be used with caution, primarily due to the added overhead of using it. You should be okay as long as the amount of scriptJobs you use are within reasonable bounds. For example, activating upon entering your tool, and deactivating afterwards is a good example of reasonable bounds, whereas monitoring 6 000 attribute changes would probably be considered a bit much. (You should test for performance for your situation)
Based on your question, I take it you’re looking to listen for when your animators select any of your controls, and might think to attach a scriptJob to each controller. This can be done, but I’d try not to attach it to each and every one, and instead try to focus them on where you really need it.
There are alternatives of course, with various pros and cons - such querying cmds.ls(selection=True) at a fixed interval and determining whether it has changed since last query.
A more common approach, than listening for events, would be to instead let your users tell your tool when they’ve got something of interest selected, upon which your tool would simply call cmds.ls(selection=True).
For example, say that I was to select a curve (functioning as a controller) and I was to broadcast a message or emit an event every time it is selected. How would I go about programming this elegantly?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dbbda77d-ab18-492c-9636-008f44394b2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB9dfaDrd8m8GMO-PcAV7iVXy1iY7-fXs4yqE0AAFMupQ%40mail.gmail.com.