[PyMEL] callback error on some controls (returns memory adress)

I have some errors and I’ve tried every single way of assigning callback functions to a tree view cmc flag. It’s supposed to pass the clicked item inside the treeview to the callback right before the contextmenu is shown, and the callback is gonna return true or false if the contextmenu should be indeed shown or not.

This is not a problem only with treeview, I’ve had the same problem with some other controls aswell. It works on simplier and more common controls such as buttons but on more advanced controls it kind of throws errors when the callback is called :frowning: the error contains the memory address of the function

I have maya 2011 hotfix 3 with PyMEL 1.0.2. Is there a workaround for this :/? I really need this function, will be used to scan the name of the items in the treeview, if they contain a “(Error)” in the start of the name, the popup will be shown and I can click autofix to fix the errors.

Thanks in advance :slight_smile:

If you wanna test it yourselves :slight_smile: Right click on an item in the treeview

// Error: <function callback at 0x0000000018F4F048> “layer 2”; //
// Error: Line 1.1: Syntax error //
// Error: <function callback at 0x0000000018F4F048> “layer 7”; //
// Error: Line 1.1: Syntax error //

#====================================================#

LIBRARIES TO IMPORT

#====================================================#
import pymel.core as pm
from maya import cmds

#====================================================#

WINDOW CREATION AND HANDLING

#====================================================#
def checkErrors(*args):
print args
return True

window = pm.window()
layout = pm.formLayout()
control = pm.treeView( parent = layout, numberOfButtons = 1, abr = False, cmc = checkErrors )
pm.popupMenu()
pm.menuItem()
pm.menuItem()
pm.menuItem()
pm.formLayout(layout,e=True, attachForm=(control,‘top’, 2))
pm.formLayout(layout,e=True, attachForm=(control,‘left’, 2))
pm.formLayout(layout,e=True, attachForm=(control,‘bottom’, 2))
pm.formLayout(layout,e=True, attachForm=(control,‘right’, 2))
pm.showWindow( window )
pm.treeView( control, e=True, addItem = (“layer 1”, “”))
pm.treeView( control, e=True, addItem = (“layer 2”, “”))
pm.treeView( control, e=True, addItem = (“layer 3”, “”))
pm.treeView( control, e=True, addItem = (“layer 4”, “”))
pm.treeView( control, e=True, addItem = (“layer 5”, “”))
pm.treeView( control, e=True, addItem = (“layer 6”, “”))
pm.treeView( control, e=True, addItem = (“layer 7”, “layer 2”))
pm.treeView( control, e=True, addItem = (“layer 8”, “layer 2”))
pm.treeView( control, e=True, addItem = (“layer 9”, “layer 2”))
pm.treeView( control, e=True, addItem = (“layer 10”, “layer 8”))
pm.treeView( control, e=True, addItem = (“layer 11”, “layer 2”))
pm.treeView( control, e=True, addItem = (“layer 12”, “”))
pm.treeView( control, e=True, addItem = (“layer 13”, “layer 10”))

I’m not sure if there is a better modern solution to that problem. In Maya 2009, the TreeView could not take python callables as Parameters. It would str the callable and try to eval that in MEL, which just plain won’t work. These UI elements are just broken. What I did to fix this at the time was make a module that would take a Python callable, store it, then build and publish a MEL function who’s sole purpose was to call back into the host module. The host module would then properly push the Callback to the desired Python function. This gets very ugly very quickly, and if you end up down this alley, I would recommend wrapping and abstracting your interface into it as quickly as possible, especially because you will get into issues of which module is responsible for the object lifetime, which is something you generally don’t want to have to be mindful of in Python.

I know that in 2011 Autodesk has added some sort of functionality to publish Python calls as MEL calls, and that may be a cleaner method than I had before. If you’re still caught up on it, I can try to elaborate further, but I cannot, unfortunately, publish the code.

Hey Lithium :slight_smile:

Been a while since I got stuck with this problem. The solution was to actually pass a mel global proc name as a string for the callback parameter with the correct number of arguments. The tree view would call the melscript function. Then I can use the mel function python(…) to delegate it BACK to my python modules objects.
Example: python(“objectEditorWindow.updateTreeViewHierarchy()”), it would search for the functions and stuff globally in the python main module I believe, that’s where my objecteEditorWindow instance defaults to anyway ^^

Though I’ve given up on the python tree view control. I’m using PyQT and QT Designer to built my own UIs. Good thing is it can easily be ported over to other apps that use Python since UIs I build in PyQT has nothing to do with Maya :slight_smile: And I’m fairly happy with the results I get from PyQT considering the amount of time I spent learning Python and the API itself, can say it’s not much time atleast ^^