Hi all,
I’ve managed to devise a method of listening in on an attribute changing, so I can respond appropriately. But I’m interested in whether there’s a more efficient way. Efficiency is my main concern in this case.
import os
import time
from maya import cmds, OpenMaya as om
# Setup scene
cmds.file(new=True, force=True)
cmds.polyCube()
# Find cube as MObject
# Is this the optimal route?
dag_path = om.MDagPath()
selection = om.MSelectionList()
selection.add("pCube1")
selection.getDagPath(0, dag_path)
m_obj = dag_path.node()
# Callback listening to changes to ANY attribute
# Is this efficient?
def callback(message_type, plug, other_plug, client_data):
if not message_type & om.MNodeMessage.kAttributeSet:
return
if "translateX" in plug.name():
print("Translate X changed!")
job = om.MNodeMessage.addAttributeChangedCallback(m_obj, callback)
#om.MMessage.removeCallback(job)
The obvious issue is how I’m listening for changes on any attribute change, rather than just the one I’m interested in, and then filtering it down. The Python callback is triggered a few more times than I’d like.
In an empty scene, without this callback, Maya is running at 1200-1300 fps (0.8ms/frame) whereas with this callback it’s running closer to 400 (2.5ms/frame).
Any ideas?
Best,
Marcus
--
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/CAFRtmOBppomMtcXWQvayoC07ht658JB2H5uZVWtnxcyHWrYynw%40mail.gmail.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/CAPGFgA2O%2Bpsyf37MdKVm6P6sGkNcsGD6hBHfNGC-6yRDJ6xK4A%40mail.gmail.com.
Is this better then a scriptJob?Yury
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACqGScgm_ZV8YLgaMHy3%3Dach1bA3YQq6bCWVyGTSE7hLdRzS0g%40mail.gmail.com.
I was just wondering how will this method compare to build- in scriptJob.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2MGV5ub16BaoRrAzgxs%3DYQypae3xfTVxbmPSUVgsvpcA%40mail.gmail.com.
Justin
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBppomMtcXWQvayoC07ht658JB2H5uZVWtnxcyHWrYynw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2O%2Bpsyf37MdKVm6P6sGkNcsGD6hBHfNGC-6yRDJ6xK4A%40mail.gmail.com.--
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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACqGScgm_ZV8YLgaMHy3%3Dach1bA3YQq6bCWVyGTSE7hLdRzS0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+unsub...@googlegroups.com.
A scriptjob is better if you need to catch attribute changed for a specific attribute (translateX in this case).
If you need to code to run when ANY attribute of a node changes, the API callback is the better bet. (Single callback vs. a scriptjob for each settable attribute of the node)
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/CAFRtmOBppomMtcXWQvayoC07ht658JB2H5uZVWtnxcyHWrYynw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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/CAPGFgA2O%2Bpsyf37MdKVm6P6sGkNcsGD6hBHfNGC-6yRDJ6xK4A%40mail.gmail.com.--
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/CACqGScgm_ZV8YLgaMHy3%3Dach1bA3YQq6bCWVyGTSE7hLdRzS0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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/CAPGFgA2MGV5ub16BaoRrAzgxs%3DYQypae3xfTVxbmPSUVgsvpcA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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/b634aad2-de3f-4845-9d47-363ef5458eb5%40googlegroups.com.