Pymel distingushing between non dag nodes with namespaces

I’ve got an annoying bug caused by the existence of two non-physical nodes (dagPoses, to be exact) with the same name but different namespaces. Pymel wants to resolve these to their short (non-namespaced) names when they are used in a callback, so any references to them crash with 'there are two objects named XXXX '. However, since they are PyNodes but not DagNodes, there is no fullpath() method on them to get the disambiguated name.

What’s a boy to do?


                fmt = lambda n : n.name().split(":")[-1]
                poses =  pm.ls(type='dagPose', l=True)
                poses.sort()
                poses = [p for p in poses if not "bindPose" in p.name()]
                for n, eachpose in enumerate(poses):
                    labeltext = fmt(eachpose)
                    btn_color = self.COLORS.get(labeltext[:2], (.5,.5, .65)) 
                    
                    yield 'pose_%s' % n,
                            pm.button( labeltext, w=120, h= 32, bgc = btn_color,
                            c= partial(self.apply, eachpose))  #<== 'boom' for nodes with namespaced twins


I’m not sure what problem you’re getting (I may just be misunderstanding you). This works for me:

from functools import partial

def printName(name):
    print 'The name -', name 
    
def main():
    namespaces = ['one', 'two']
    for ns in namespaces:
        pm.namespace(add=ns)
        pm.createNode('dagPose', n=':%s:dag' % ns)

    poses =  pm.ls(type='dagPose')
    poses.sort()
    poses = [p for p in poses if not "bindPose" in p.name()]
    for n, eachpose in enumerate(poses):
        yield 'pose_%s' % n, partial(printName, eachpose)  #<== 'boom' for nodes with namespaced twins
        
for name, func in main():
    func()

# The name - one:dag
# The name - two:dag

EDIT:
I thought maybe it was some weird callback behavior that would only show up for UIs so I tried adding the callback as a button command similar to what you have and it still worked for me

Maybe the issue is in your apply method?

I think that the problem might be with duplicate buttons and not dagPose nodes. The labeltext doesn’t only give the label to the buttons but also an internal name in maya and that causes the crash.

EDIT:
Try using the “label” flag for the button command. label = labeltext instead of just labeltext. That way maya will automatically asign a different internal name to your buttons and the labels can be the same.

ah, that’s right. I usually use label by reflex but I clearly did not this time. That did the trick. It would have been easier to debug if the error did not seem to emanate from several layers deeper in the stack than the actual line. Curse you, pm.factories…

Thanks guys!