Search code examples
c++maya

How to add a button to my node's Attribute Editor panel, which calls a method within that node?


I have a node that I'd like to add a button to within it's Attribute Editor panel, such that when the user clicks on said button, a method belonging to the node is called.

I have some knowledge of creating custom commands and making Attribute Editor templates, but I'm not sure how to specifically call a method within the node class (and not a custom registered command or MEL function), nor how to add a button with the C++ API.


Solution

  • To add buttons you need to use the corresponding MEL commands. You can use the MGlobal::executeCommand function to use them from C++.

    See the documentation for the button command for how to create buttons with actions.

    To call a method from your C++ code you need to create a command for it by implementing MPxCommand and registering your class with MFnPlugin.registerCommand. Then you can run it everwhere where MEL commands can be run.