Out of curiosity, what are the performance numbers like when your callback simply does nothing and passes? I am wondering if the required checks in your function body are slow, or if simply using a python-based callback is the slow part in the first place.
Justin On Fri, Apr 29, 2016 at 8:25 AM Marcus Ottosson <[email protected]> wrote: > 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 osimport timefrom 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 > > -- > *Marcus Ottosson* > [email protected] > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBppomMtcXWQvayoC07ht658JB2H5uZVWtnxcyHWrYynw%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBppomMtcXWQvayoC07ht658JB2H5uZVWtnxcyHWrYynw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2O%2Bpsyf37MdKVm6P6sGkNcsGD6hBHfNGC-6yRDJ6xK4A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
