Did some searching and didn’t find an answer. I’m sure this is something other folks have come into and I’m interested in how you handle it.
Problem: In maya, a message node on a local object connected to a referenced object gets a truncated message on scene reload.
For example, ‘obj1’ has a message attribute connected to ‘ref1:obj2’ in the scene. Then the scene is saved, closed and reopened. The message now returns ‘ref1:’ . My tester reported this in 2012. I tested in 2011 and 2013 and verified.
Also, the connection is both ways to illustrate what works and what’s broken after file repoen:
'obj1 ’ =broken=> ‘ref1:obj2’
‘ref1:obj2’ ==> ‘obj1’
My question is if there is a way to tell maya to refresh that message connection? I have a working solution to getting the info another way but if there’s a simple solution I’d rather not have to retool a large chunk of code. After all, that’s what I thought point of a message node was for.
Could you post an example file? I can’t recreate this in 2012.
I have a cube referenced into a scene with a cylinder. I tried connecting the cylinder’s message to a custom message attribute on the referenced box and vice verse. Both cases after saving/reloading, listConnections returned the full name of the referenced object.
the connection that breaks is on the locator. Attribute is ‘cgmName’. I believe the one I uploaded has already had the reload break. It always drops to the ref prefix and that what listConnections returns. Again, the message attr on the reference object stays connected fine. It’s the other direction that breaks.
Just tested it again myself in 2012. Same issue. It also drops the connections when you just unload and reload the reference.
Sorry I wasn’t more clear. I meant to originally to thank you for trying but the issue still remained. That’s what my demo code was for. That’s the broken connection.
I have a working solution now. It needs to be optimized and cleaned but it’s functioning. Also, it’s using some of our own libraries so some functions you wouldn’t have - mainly reporting and a connection function that ignores locks and other stuff - fyi.
import maya.cmds as mc
def repairMessageToRefObject(obj,attr,debug=True):
"""
To be repairable, there must have been a message connection both directions.
Assertions -
1) Target Attribute must be a message attribute
2) Target is connected to a reference node
Returns -
Success(bool)
"""
targetAttr = "%s.%s"%(obj,attr)
assert mc.attributeQuery (attr,node=obj,msg=True), "'%s' isn't a message attribute. Aborted"%targetAttr
objTest = mc.listConnections(targetAttr, p=1)
assert mc.objectType(objTest[0]) == 'reference',"'%s' isn't returning a reference. Aborted"%targetAttr
ref = objTest[0].split('RN.')[0] #Get to the ref
if debug:guiFactory.report("Reference connection found, attempting to fix...")
messageConnectionsOut = mc.listConnections("%s.message"%(obj), p=1)
if messageConnectionsOut and ref:
for plug in messageConnectionsOut:
if ref in plug:
matchObj = plug.split('.')[0]#Just get to the object
doConnectAttr("%s.message"%matchObj,targetAttr)
if debug: guiFactory.report("'%s' restored to '%s'"%(targetAttr,matchObj))
if len(messageConnectionsOut)>1:#fix to first, report other possibles
if debug: guiFactory.warning("Found more than one possible connection. Candidates are:'%s'"%"','".join(messageConnectionsOut))
return True
return False