scriptJob event for referenceUnloaded

167 views
Skip to first unread message

Kyle Burris

unread,
Dec 3, 2015, 11:06:08 AM12/3/15
to Python Programming for Autodesk Maya
I'm trying to trigger a UI refresh function when a referenced file is loaded and unloaded. The 'PostSceneRead' scriptJob event works great for loading, but I can't find a way to trigger a command when a reference is unloaded. I tired putting attributeChanged on a bunch of different attrs on the referenceNode, but that didn't work.

I stumbled on something online where someone was suggesting taking an attribute from a referenced node and then attaching a scriptJob to it with the attributeDeleted event. However since the files might not share any common attributes I'd have to randomly select a node.attr per referenced file and attach a scriptJob to it. That approach could work but seems clunky to me.

Anyone have any ideas?

Thanks,
Kyle

Nicolas Combecave

unread,
Dec 3, 2015, 2:57:55 PM12/3/15
to python_in...@googlegroups.com

Recently, I used those two methods in a class creating an ui.
Maybe you could use them to get started...
RegisterCallbacks should be passed the string value of your main ui window I guess, even if it should work with any other type of ui element.

import maya.OpenMayaUI as omUI
import maya.OpenMaya as om

def theCallback(*args):
    pass

def registerCallbacks(attachCbToThisUi):
    createdCallBacks = []
    createdCallBacks.append(om.MSceneMessage.addCallback(om.MSceneMessage.kAfterCreateReference, theCallback, 'someData'))
    createdCallBacks.append(om.MSceneMessage.addCallback(om.MSceneMessage.kAfterLoadReference,   theCallback, 'someData'))
    createdCallBacks.append(om.MSceneMessage.addCallback(om.MSceneMessage.kAfterRemoveReference, theCallback, 'someData'))
    createdCallBacks.append(om.MSceneMessage.addCallback(om.MSceneMessage.kAfterUnloadReference, theCallback, 'someData'))

    omUI.MUiMessage.addUiDeletedCallback(attachCbToThisUi, removeCallbacks, createdCallBacks)

    return createdCallBacks

def removeCallbacks(cbIdsToRemove):
    for cbId in cbIdsToRemove:
        om.MMessage.removeCallback(cbId)

--
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/e1193bf7-8016-40c0-a2a8-33f2c132fe1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicolas Combecave

unread,
Dec 8, 2015, 2:40:21 AM12/8/15
to python_in...@googlegroups.com
Hi Kyle,
Any success with those callbacks?

Kyle Burris

unread,
Dec 8, 2015, 1:25:20 PM12/8/15
to Python Programming for Autodesk Maya
Hi Combi,

Thanks for the reply, that looks really useful. I've had this page open as a tab in firefox for a week now, but production priorities changed and I haven't been able to touch the tool I was working on. I'll make a point of replying here once I get the time to take a stab at it.

Thanks again

Nicolas Combecave

unread,
Dec 8, 2015, 2:27:22 PM12/8/15
to python_in...@googlegroups.com
Yeah, I understand, job priorities are sometimes very pressing!
What I could say is that once you touch maya Python API, difficult to come back from it!
--
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.

Kyle Burris

unread,
Jan 26, 2016, 11:48:27 AM1/26/16
to Python Programming for Autodesk Maya
I finally had some time today to give this a go.

The kAfterUnloadReference worked great, but i found that the addUIDeletedCallBack only worked when the ui was deleted with code, and not when the X close button was pressed. So I was having a problem with callback trying to refresh a ui that wasn't there. Apparently when the X close button is clicked the ui is hidden, I think it still exists in some capacity, but was still causing my refresh function to fail. To get around this I got rid of the addUIDeletedCallBack and overrided the qt hideEvent function, and had that call removeCallbacks.

Thanks again for the help
Kyle


On Tuesday, December 8, 2015 at 2:27:22 PM UTC-5, combi wrote:
Yeah, I understand, job priorities are sometimes very pressing!
What I could say is that once you touch maya Python API, difficult to come back from it!

Le mardi 8 décembre 2015, Kyle Burris <kyleb...@gmail.com> a écrit :
Hi Combi,

Thanks for the reply, that looks really useful. I've had this page open as a tab in firefox for a week now, but production priorities changed and I haven't been able to touch the tool I was working on. I'll make a point of replying here once I get the time to take a stab at it.

Thanks again

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

Nicolas Combecave

unread,
Jan 26, 2016, 11:50:38 AM1/26/16
to python_in...@googlegroups.com
Glad it helped, Kyle!


2016-01-26 17:48 GMT+01:00 Kyle Burris <kyleb...@gmail.com>:
I finally had some time today to give this a go.

The kAfterUnloadReference worked great, but i found that the addUIDeletedCallBack only worked when the ui was deleted with code, and not when the X close button was pressed. So I was having a problem with callback trying to refresh a ui that wasn't there. Apparently when the X close button is clicked the ui is hidden, I think it still exists in some capacity, but was still causing my refresh function to fail. To get around this I got rid of the addUIDeletedCallBack and overrided the qt hideEvent function, and had that call removeCallbacks.

Thanks again for the help
Kyle

On Tuesday, December 8, 2015 at 2:27:22 PM UTC-5, combi wrote:
Yeah, I understand, job priorities are sometimes very pressing!
What I could say is that once you touch maya Python API, difficult to come back from it!

Le mardi 8 décembre 2015, Kyle Burris <kyleb...@gmail.com> a écrit :
Hi Combi,

Thanks for the reply, that looks really useful. I've had this page open as a tab in firefox for a week now, but production priorities changed and I haven't been able to touch the tool I was working on. I'll make a point of replying here once I get the time to take a stab at it.

Thanks again

--
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/1c4cce54-ad12-47e1-8e3d-f2711564ae0a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages