Change Event for Scene?

321 views
Skip to first unread message

Kevin C. Burke

unread,
Oct 9, 2016, 4:33:27 PM10/9/16
to Python Programming for Autodesk Maya

Hi,
I have a list that I want to update when objects have been added or deleted from the Maya scene.


Is there some kind of global event or perhaps an Outliner event that fires when a change like this happens?


I am working in PyMel. Thank you! :)

Justin Israel

unread,
Oct 9, 2016, 4:41:59 PM10/9/16
to Python Programming for Autodesk Maya
Hi,

Take a look at scriptJobs. There are events for when DAG nodes are created, and when nodes are deleted. scriptJob is effectively a high level wrapper around MMessage callbacks.

Justin


--
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/6a3f27b3-02fa-450e-83cf-69c7f200d45c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin C. Burke

unread,
Oct 9, 2016, 4:48:07 PM10/9/16
to Python Programming for Autodesk Maya
Hi Justin,
Thanks a lot for the quick reply!!! I found the event "DagObjectCreated" for when an object is created; am I missing the equivalent for when they are removed?

Thank you!


On Sunday, October 9, 2016 at 1:41:59 PM UTC-7, Justin Israel wrote:
Hi,

Take a look at scriptJobs. There are events for when DAG nodes are created, and when nodes are deleted. scriptJob is effectively a high level wrapper around MMessage callbacks.

Justin


On Mon, Oct 10, 2016 at 9:33 AM Kevin C. Burke <kevin...@gmail.com> wrote:

Hi,
I have a list that I want to update when objects have been added or deleted from the Maya scene.


Is there some kind of global event or perhaps an Outliner event that fires when a change like this happens?


I am working in PyMel. Thank you! :)

--
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.

Justin Israel

unread,
Oct 9, 2016, 4:54:05 PM10/9/16
to python_in...@googlegroups.com
On Mon, Oct 10, 2016 at 9:48 AM Kevin C. Burke <kevin...@gmail.com> wrote:
Hi Justin,
Thanks a lot for the quick reply!!! I found the event "DagObjectCreated" for when an object is created; am I missing the equivalent for when they are removed?


Thank you!


On Sunday, October 9, 2016 at 1:41:59 PM UTC-7, Justin Israel wrote:
Hi,

Take a look at scriptJobs. There are events for when DAG nodes are created, and when nodes are deleted. scriptJob is effectively a high level wrapper around MMessage callbacks.

Justin


On Mon, Oct 10, 2016 at 9:33 AM Kevin C. Burke <kevin...@gmail.com> wrote:

Hi,
I have a list that I want to update when objects have been added or deleted from the Maya scene.


Is there some kind of global event or perhaps an Outliner event that fires when a change like this happens?


I am working in PyMel. Thank you! :)





--

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.
--

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/86bb5514-2390-4a7d-b54a-bfe1c3f56e58%40googlegroups.com.

Kevin C. Burke

unread,
Oct 9, 2016, 5:04:39 PM10/9/16
to Python Programming for Autodesk Maya
Thanks again for the reply! You've been very helpful.

I have a follow-up question...DagObjectCreated will fire when any object is created. Am I correct that I'd need to specify a node for nodeDeleted to fire? e.g.
cmds.scriptJob(nodeDeleted=["pCube1",myFunction])

I only ask because it seems very resource-intensive to add a scriptJob to every object in the scene to detect a node deletion.

Thanks!

On Sunday, October 9, 2016 at 1:54:05 PM UTC-7, Justin Israel wrote:
On Mon, Oct 10, 2016 at 9:48 AM Kevin C. Burke <kevin...@gmail.com> wrote:
Hi Justin,
Thanks a lot for the quick reply!!! I found the event "DagObjectCreated" for when an object is created; am I missing the equivalent for when they are removed?

 

Thank you!


On Sunday, October 9, 2016 at 1:41:59 PM UTC-7, Justin Israel wrote:
Hi,

Take a look at scriptJobs. There are events for when DAG nodes are created, and when nodes are deleted. scriptJob is effectively a high level wrapper around MMessage callbacks.

Justin


On Mon, Oct 10, 2016 at 9:33 AM Kevin C. Burke <kevin...@gmail.com> wrote:

Hi,
I have a list that I want to update when objects have been added or deleted from the Maya scene.


Is there some kind of global event or perhaps an Outliner event that fires when a change like this happens?


I am working in PyMel. Thank you! :)





--

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.




--

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.

Justin Israel

unread,
Oct 9, 2016, 5:25:43 PM10/9/16
to python_in...@googlegroups.com
On Mon, Oct 10, 2016 at 10:04 AM Kevin C. Burke <kevin...@gmail.com> wrote:
Thanks again for the reply! You've been very helpful.

I have a follow-up question...DagObjectCreated will fire when any object is created. Am I correct that I'd need to specify a node for nodeDeleted to fire? e.g.
cmds.scriptJob(nodeDeleted=["pCube1",myFunction])

I only ask because it seems very resource-intensive to add a scriptJob to every object in the scene to detect a node deletion.

It would depend on what your application is. When you are notified about nodes being created, if your goal was to inspect them and conditionally want to register interested when particular nodes are removed, then you could go with the script job.

If you want to know when any node is removed, then you could move to the Maya API and use the MDGMessage callbacks directly:

import maya.OpenMaya as om

def node_added(node, *args):
    print "added!", node

def node_removed(node, *args):
    print "removed!", node

add_id = om.MDGMessage.addNodeAddedCallback(node_added)
rem_id = om.MDGMessage.addNodeRemovedCallback(node_removed)

Now you can receive an MObject and inspect each one to take action.

Justin
 

Thanks!

On Sunday, October 9, 2016 at 1:54:05 PM UTC-7, Justin Israel wrote:
On Mon, Oct 10, 2016 at 9:48 AM Kevin C. Burke <kevin...@gmail.com> wrote:
Hi Justin,
Thanks a lot for the quick reply!!! I found the event "DagObjectCreated" for when an object is created; am I missing the equivalent for when they are removed?

 

Thank you!


On Sunday, October 9, 2016 at 1:41:59 PM UTC-7, Justin Israel wrote:
Hi,

Take a look at scriptJobs. There are events for when DAG nodes are created, and when nodes are deleted. scriptJob is effectively a high level wrapper around MMessage callbacks.

Justin


On Mon, Oct 10, 2016 at 9:33 AM Kevin C. Burke <kevin...@gmail.com> wrote:

Hi,
I have a list that I want to update when objects have been added or deleted from the Maya scene.


Is there some kind of global event or perhaps an Outliner event that fires when a change like this happens?


I am working in PyMel. Thank you! :)





--

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.




--

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.
--

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/34397c23-08a8-4c86-8106-ff7fb3672fb7%40googlegroups.com.

Kevin C. Burke

unread,
Oct 9, 2016, 5:31:28 PM10/9/16
to Python Programming for Autodesk Maya
This is exactly what I needed, Justin, thank you so much
Justin
 
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.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.




--

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.

Justin Israel

unread,
Oct 9, 2016, 5:35:38 PM10/9/16
to Python Programming for Autodesk Maya


On Mon, 10 Oct 2016, 10:31 AM Kevin C. Burke <kevin...@gmail.com> wrote:
This is exactly what I needed, Justin, thank you so much

Welcome! 

Justin
 
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.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.




--

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.

--
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/1184b5e1-d9f1-42f0-bef6-8bcfc29b533a%40googlegroups.com.

Joe Weidenbach

unread,
Oct 9, 2016, 6:58:34 PM10/9/16
to Python Programming for Autodesk Maya
The only thing I would add to this is to remember to remove your callback when you're done with it, otherwise Maya can have issues with potential crashes, for example if you've closed your UI but the callback is still in place. I'm not positive that this is as critical in the python side as it is on the C++ side, but it's a good practice at the very least.

Kevin C. Burke

unread,
Oct 9, 2016, 7:20:12 PM10/9/16
to Python Programming for Autodesk Maya
Hi Joe!
Thanks for weighing in. I have experienced exactly what you're describing already.

I need the callbacks to fire as long as my script's window is open. Do you know of an event that fires when my window is closed? I could remove the callbacks then?

Justin
 
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.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.




--

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.

--
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.

--
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.

Kevin C. Burke

unread,
Oct 9, 2016, 7:34:10 PM10/9/16
to Python Programming for Autodesk Maya
Found it here - I'm using PyMel's dockControl.

closeCommand

Thanks for the tip, Joe!
Reply all
Reply to author
Forward
0 new messages