maya_mel转python代码插件
这个⼯具,因该是像我这种懒⼈的福⾳啦,我是⼀个maya mel程序⽼⽤户了,算起来有10多年了,python现在逐渐成为主流DCC接⼝语⾔,但⼈都有惰性,⽽且mel是maya内置的native语⾔,⼀般⼯作所需都够⽤了,但python流⾏除了语法精炼外,还有其跨平台兼容想好的优点,所以⼀套ui⽂件,可以应⽤在不同的软件⾥使⽤。那其实python只不过将mel脚本转义为python脚本,⽽且是对应的关系,甚⾄作为第三⽅maya python脚本pymel语⾔其实更加的python风格化,直接提供了mel转换为python代码的功能。
从此mel程序员解脱了… 哈哈哈哈哈哈哈哈哈哈哈哈 … 坏了收不住了…哈哈哈…
本套插件使⽤的就是这个pymel中tools包的mel2py模块功能:
maya中的插件界⾯如下:
ezMel2Python.py 内容如下:
# -*- coding: utf-8 -*-
import os
as pm
ls.mel2py as mel2py
def em2pConvMel2Py():
u'''translate MEL to Python'''
melCmd = pm.scrollField( 'em2pTextEditMEL', q=1,tx=1 )
pyCmd = l2pyStr(melCmd,pymelNamespace='pm')
pyFixed = place("pymel.all","")
pm.scrollField( 'em2pTextEditPy', e=1,tx=pyFixed )
def ezMel2Python():
try:
em2pUIFile = os.path.abspath( __file__ ).split('.')[0] + '.ui' # same folder this script
except:
print u'Error,can\'t load UI.'
return
if pm.window('ezMel2PyWin', exists=1) :
pm.deleteUI( 'ezMel2PyWin' )
ezMel2PythonWindow = pm.loadUI( uiFile = em2pUIFile )
pm.showWindow( 'ezMel2PyWin' )
pm.window('ezMel2PyWin',e=1,tlc=(200,250) )
ezMel2Python.ui ⽂件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<ui version="4.0">
<class>ezMel2PyWin</class>
<widget class="QDialog" name="ezMel2PyWin">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1212</width>
<height>493</height>
</rect>
</property>
<property name="windowTitle">
<string>Translate MEL to Python</string>
</property>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>1191</width>
<height>401</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="0" column="0">
<widget class="QTextEdit" name="em2pTextEditMEL"/>
</item>
<item row="0" column="1">
<widget class="QTextEdit" name="em2pTextEditPy"/>
</item>
</layout>
</widget>
<widget class="QPushButton" name="em2pConvMel2PyBtn">
<property name="geometry">
<rect>
<x>460</x>
<y>440</y>
<width>301</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>>>> Translate MEL to Python</string>
python代码转换
</property>
<property name="+command" stdset="0">
<string>"import 2pConvMel2Py()"</string> </property>
</widget>
<widget class="QLabel" name="em2pLabel">
<property name="geometry">
<rect>
<x>60</x>
<y>450</y>
<width>271</width>
<height>21</height>
</rect>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
</property>
<property name="text">
<string>Paste MEL Code to above text are.</string>
</property>
</widget>
<widget class="QLabel" name="em2pLabelMEL">
<property name="geometry">
<rect>
<x>150</x>
<y>10</y>
<width>50</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>MEL</string>
</property>
</widget>
<widget class="QLabel" name="em2pLabelPython">
<property name="geometry">
<rect>
<x>710</x>
<y>10</y>
<width>161</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Python (pymel)</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
global proc ezMel2Python()
{
python("import ezMel2Python");
python("Mel2Python()");
}
ezMel2Python;
将以上三个代码⽂件,拷贝到maya ⽤户 scripts下,之后打开maya,将插件l托⼊maya即可弹出插件界⾯。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论