How to add custom attribute to AETemplate with python?

1,173 views
Skip to first unread message

yaoyansi

unread,
Apr 27, 2014, 1:19:23 AM4/27/14
to maya_he3d
hi all,
I use Maya2013 and later version, and I'm trying add my own attributes to the following node types:
- maya transform node,
- maya mesh shape node,
- maya light shape node,
- maya camera shape node,
- maya shader node(e.g. bump2d, place2dTexture, and etc),
- maya shading group node
- my custom node,

My question are:
1. how to implement AETemplate of my custom node in Python? and which is the best(or simplest)?
I saw maya devkit provides these files:
$Maya2013\devkit\other\pymel\examples\AETemplates.py and $Maya2013\devkit\other\pymel\examples\customClasses.py
But I'm not sure if they are what exactly I need.

2. Mentalray add its custom attributes in the "mentalray" section in each AETemplate.
how to add my custom attributes in my custom section(e.g. "MyRenderer") in each AETemplateof Maya node(e.g. transform node, mesh shape node, maya shader node)? and which is the best(or simplest)?


Regards


haggi krey

unread,
Apr 27, 2014, 9:23:11 AM4/27/14
to maya...@googlegroups.com, yaoyansi
That's quite easy. You can simple register a AETemplateCustomContent callback.

pm.callbacks(addCallback=myTemplateCallback, hook='AETemplateCustomContent', owner=self.pluginName)

Your myTemplateCallback looks like this (done with pymel):

import pymel.core as pm
import logging

log = logging.getLogger("ui")

class BaseTemplate(pm.ui.AETemplate):
   
    def addControl(self, control, label=None, **kwargs):
        pm.ui.AETemplate.addControl(self, control, label=label, **kwargs)
       
    def beginLayout(self, name, collapse=True):
        pm.ui.AETemplate.beginLayout(self, name, collapse=collapse)


class AECoronaNodeTemplate(BaseTemplate):
    def __init__(self, nodeName):
        BaseTemplate.__init__(self,nodeName)
        self.thisNode = None
        self.node = pm.PyNode(self.nodeName)
        self.buildBody(nodeName)
        log.debug("AECoronaNodeTemplate")
   def buildBody(self, nodeName):
        if pm.PyNode(nodeName).type() == "mesh":
              self.beginLayout("MyLayout")
              self.endLayout()

The rest follows the normal AETemplate structure. If you need some examples, you can have a look here:

https://github.com/haggi/OpenMaya/blob/master/src/mayaToCorona/mtco_devmodule/scripts/Corona/AETemplate/AECoronaSurfaceTemplate.py

yaoyansi

unread,
May 7, 2014, 10:42:26 AM5/7/14
to maya_he3d
Hi haggi,
Thanks for your reply, and I'm very glad to see your OpenMaya supports so many renderers now. It's awosome, Man! :)

I'm sorry but I'm still confused on my problem. I don't know how to register myTemplateCallback.
I read the maya doc, but it's still not clear to me.

My question are:
1. Is myTemplateCallback a function or a class?
2. How you register AECoronaNodeTemplate?
3. Where you call pm.callbacks(addCallback=.., hook='AETemplateCustomContent', ...) in OpenMaya?

Regards
------------------------------------------------------------------
发件人:haggi krey <haggi...@gmail.com>
发送时间:2014年4月27日(星期日) 21:23
收件人:maya_he3d <maya...@googlegroups.com>
抄 送:yaoyansi <yaoy...@aliyun.com>
主 题:[maya_he3d] Re: How to add custom attribute to AETemplate with python?

--
You received this message because you are subscribed to the Google Groups "maya_he3d" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maya_he3d+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

haggi krey

unread,
May 8, 2014, 6:29:10 AM5/8/14
to maya...@googlegroups.com, yaoyansi

Thanks, the project is growin :)

Okay the callback itself is a simple function which receives the node name as argument. So a simple

def myCallback(nodeName):
    print "mycallback"

Shoud work. You can define the callback whenever you want. In my plugins I call a initialize script from a c++ plugin during the load process of the plugin. Then in the initialize script I exectute the:
pm.callbacks(addCallback=myCallback, hook='AETemplateCustomContent', ...)

In the same scripts I register the AETemplates. Normally pymel finds the AETemplates automatically. The problem is that it only finds the very first AETemplates directory. So if you have more than only one AETemplate directory, they are not available. For this reason I load them manually.

The load procedure is located here - line 506:
https://github.com/haggi/OpenMaya/blob/master/src/mayaToCorona/mtco_devmodule/scripts/mtco_initialize.py

In line 491 you can find the aeTemplateCallback. The callback simply calls the user AE template.
Reply all
Reply to author
Forward
0 new messages