Mel to Python conversion

370 views
Skip to first unread message

likage

unread,
Jul 6, 2016, 12:42:13 PM7/6/16
to Python Programming for Autodesk Maya
Hi all, I am trying to convert the following Mel into python but was met with some trouble.
Though I do not intend to implement the code, still, I would like to be enlighten, shedding some light as I am trying to learn / be knowledgeable in both Mel and Python..

The following is the Mel code:
string $window = `window -title "Long Name" -iconName "Short Name"`;
columnLayout
-adjustableColumn true;


// this is maya's global variable of all the preset film backs
global string $gFilmbackTable[];


// create an option menu that will contain all the preset film backs
optionMenu
- l "Film Gate" omFilmbackMenu;


// grab the film backs in the table and add them to the drop down menu
for($i=0; $i < size($gFilmbackTable); $i += 3) {
menuItem
-l $gFilmbackTable[$i];
}

showWindow $window
;

And the following is the converted Python that I did:
import maya.cmds as cmds
import maya.mel as mel


win
= cmds.window(title = "Long Name", iconName = "Short Name", widthHeight = (200, 55))
cmds
.columnLayout(adjustableColumn = True)


fbTable
= mel.eval('global string $gFilmbackTable[]')
# fbValues = mel.eval('$gFilmbackTable')


cmds
.optionMenu("omFilmbackMenu", label = "Film Gate")


cmds
.showWindow(win)


First problem that I had, is grabbing the value of $gFilmbackTable. As I tried printing them out (fbValues), it either prompts me error saying - RuntimeError: Error occurred during execution of MEL script

Whereas in Mel tab, it is able to print out a list of things.. Guess I screwed up somewhere?

The second issue that I had would be converting the for statement (and onwards) in Mel to python. While I can think of replacing 'size' with 'len', but the other parameters within - $i=0 and $i += 3, how do I do so in Python?

Kurian O.S

unread,
Jul 6, 2016, 1:01:12 PM7/6/16
to python_in...@googlegroups.com
import maya.cmds as cmds
import maya.mel as mel

win = cmds.window(title = "Long Name", iconName = "Short Name", widthHeight = (200, 55))
cmds.columnLayout(adjustableColumn = True)

fbTable = mel.eval('$tempFbValList = $gFilmbackTable')
print fbTable

cmds.optionMenu("omFilmbackMenu", label = "Film Gate")

# If you want all
#for eachItm in rfbTable:
#    cmds.menuItem(label=eachItm)

for eachItm in range(0, len(fbTable), 3):
    cmds.menuItem(label=eachItm)

cmds.showWindow(win)

You can use range to do the increment. And hope this helps




--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c8c039f0-dfa9-4372-abd9-9ab26453724e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--:: Kurian ::--
Reply all
Reply to author
Forward
0 new messages