AETemplate to add custom functions

147 views
Skip to first unread message

vince touache

unread,
Aug 10, 2023, 12:00:49 PM8/10/23
to Python Programming for Autodesk Maya
hello, 

I'm trying to create some specific widgets in an AEtemplate. While I was almost sure I had to do it in PySide with a hack, it turns out Maya provides (on paper) everything needed.
I can't find any exhaustive documentation on the xml tags expected by an AEtemplate.xml, just the existing examples.

1. What's the benefit of using xml over mel? It seems that xml is the proper way, as per Autodesk, but at least Mel is somewhat documented...

2. What's the matter with all the views ? "look", "default", "anim", etc.... ? I never noticed that before. What if I want my AEtemplate to affect the default view and only the default view?

3. To create a callback in the AEtemplate, linked to a custom python script, you can use
<description language="cb">py.{file_name}.{function_name}</description>. I managed to make it work once, so I know it is doable. However, no way to make it work again, and since everything fails totally silently (which the core of my problem and what's been driving me crazy for the past few days), I have no idea what I'm doing wrong.
Here is what I have:

Maya.env:
MAYA_CUSTOM_TEMPLATE_PATH = $MAYA_APP_DIR:$MAYA_SCRIPT_PATH:/Users/{me}/Library/Preferences/Autodesk/maya/2024/scripts
PYTHONPATH = /Users/{me}/Library/Preferences/Autodesk/maya/2024/scripts

.../Preferences/Autodesk/maya2024/scripts/AEtransform.fooTemplate.xml (my script folder):
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <templates>
  3.   <using package='maya'/>
  4.   <template name='AEtransform'>
  5.     <!-- WORKS -->
  6.     <attribute name='translateX' type='maya.doubleLinear'>
  7.       <label>Translate X</label>
  8.     </attribute>
  9.     <!-- WORKS (apparently, doubleLinear or float are the same) -->
  10.     <attribute name='translateY' type='maya.float'>
  11.       <label>Translate Y</label>
  12.     </attribute>
  13.     <!-- DOESN'T WORK -->
  14.     <attribute name='custom_attr' type='maya.float'>
  15.       <label>Custom Attr</label>
  16.       <description language="cb">
  17.           py.AEaddFloatSlider.AEaddFloatSliderModule
  18.       </description>
  19.     </attribute>
  20.   </template>
  21.  
  22.   <view name="Anim" template="AEtransform">
  23.     <property name='translateX'/>
  24.     <property name='translateY'/>
  25.     <property name='custom_attr'>
  26.     </property>
  27.   </view>
  28. </templates>

.../Preferences/Autodesk/maya2024/scripts/AEaddFloatSlider.py
  1. import maya.cmds as cmds
  2.  
  3. def AEaddFloatSliderModule( plug, sliderLabel, annot ):
  4.     cmds.rowLayout( nc=2 )
  5.     val = cmds.getAttr( plug )
  6.     cmds.text( label=sliderLabel )
  7.     slider = cmds.floatSlider( annotation=annot, v=val )
  8.     def AEaddFloatSliderModuleCB( *args ):
  9.         val = cmds.floatSlider( slider, q=1, v=1 )
  10.         cmds.setAttr( plug, val )
  11.     cmds.floatSlider( slider, e=1, cc=AEaddFloatSliderModuleCB )
  12.     cmds.setParent( u=1 )

Inside maya:
cmds.createNode('transform', n='foo')
cmds.addAttr('foo', ln='custom_attr', at='float')


If anyone has any idea of why this is not working (or how I could get some sort of verbosity from maya), that will be more than appreciated!

Thank you so much
Reply all
Reply to author
Forward
0 new messages