PDA

View Full Version : metaprogramming MEL: metaMel!


EdtheHobbit
11-14-2012, 11:05 PM
I've started working on a metaprogramming system for MEL, as part of a larger "open pipeline" project. I figured I'd document my progress here.

The first goal is to build an on-the-fly script / UI generator in MEL (and possibly Python for some tasks)

I'm leaning towards XML as my initial model, so my first task will be to write MEL scripts for reading, writing, and manipulating XML.

I'm going to combine this with Maya-centric methods for getting variables from the user or maya environment -- so even the base templates can be automated to some degree.

The whole shebang is going to be recursive as well, so you can have an xml document that triggers calls to other documents to supply content.

I'm hoping that the final, final product of all this will be a way for amateurs, students, and small studios to set up pipeline tools capable of being customized down to variable names. The user only has to set up the initial conditions, and the metaPipe will take care of the rest.

ldunham1
11-15-2012, 07:52 AM
just curious, any reason your not using python handsdown for it?
For starters I've found python for xml handling far easier and more effiecient than using mel.

Mark-J
11-15-2012, 08:25 AM
Have to ask the same thing, why mel? For pure metaData programming you really need Python and class structures to make the most of data. Mel is good, I've got nothing against it, but once you switch to Python you'll never look back.

EdtheHobbit
11-15-2012, 04:22 PM
I wholeheartedly agree, actually. Python would be the logical choice, and a lot less painful on the whole. Python probably should be the meta-language. But... for whatever reason, the idea of using a meta-language that is the same as the destination language is wonderfully endearing to me. So, for the MEL portions of the code, I'm going to use MEL meta-code. I'll probably end up doing a python interpreter as well, for the python portions of the code.

EdtheHobbit
11-15-2012, 04:24 PM
And, I should probably add, this is a personal project -- if I was on a deadline or handing this to a supervisor, I'd use Python in a heartbeat.

katisss
11-15-2012, 04:29 PM
Mel is only good for shelves and AETemplates now.
+1 for python

giordi
11-15-2012, 04:35 PM
Mel is only good for shelves and AETemplates now.
+1 for python

exactly , i don't use mel since like 3 years now for a pipeline python is the way to go , regardles the easier use and so on with python you can trigger so many libraries to help your work .
Example even the XML is obsolete if you use python you can easly use JSON or PICKLE and avoid all the pain coming from XML

EdtheHobbit
11-15-2012, 05:23 PM
Python is great. Won't argue about that.

I'm starting with MEL for a very good reason. This is a learning exercise and will ultimately be a teaching tool, and as much as I appreciate the input, I'm well aware that I'm going in the less-than-optimal direction starting out. If I don't struggle through the MEL first, I won't fully understand (and can't teach) the differences between the procedural and object-oriented approaches to this kind of problem.

So, settle down, I hear ya!

katisss
11-15-2012, 05:55 PM
Teaching loves the past. I remember my Pascal lecture as quite useless.
But so great for teaching...

Stoehr
11-15-2012, 07:26 PM
Ed,

I hear ya. As a fellow educator, I'm also learning MEL and Python, so I can knowledgeably explain the nuances and differences. So, students understand where and when to use MEL or Python. It is very important to the history of Maya and 3D in general. Many of the developments in neighboring programs are born from solving problems in Maya. I'd love to hear your experiences, and trade info with you.

I'm currently stuck on the same idea, how to implement meta-data in MEL. Specifically following this technical artist from Bungie. (http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=0CFMQFjAD&url=http%3A%2F%2Fwww.gdcvault.com%2Fplay%2F1708%2FModular_Procedural_Rigging&ei=HE-lUNSqDKL7iwLJlIGgCw&usg=AFQjCNEV553-fwKs0wwjKbi7szbC46OnJw&sig2=jcHBcUfsu_pm-Uftz4AXKA&cad=rja) Interestingly, this was presented in 2009, so only 3 years ago, and is entirely in MEL.

Love to hear your thoughts.

EdtheHobbit
11-15-2012, 09:52 PM
So here's the initial challenge that I'm setting myself. I want to interpret this xml into a fully-functioning mel file that creates a floating, resizeable window with two buttons. The buttons' colors will be set with a modal window described in a mel file. The get'...' method will set the variable, and the use'...' method will re-use it.

This xml will build a script, but I'm thinking that I can use the same idea to build other maya objects and assets, such as scenes, characters, rigs, etc.


<metaMel type="script">

<header>
<title>
my MEL tool
</title>
<version>
v 1.0
</version>
</header>

<procComment>
This is my tool's first procedure
</procComment>

<procedure name="myProc">
<floatingWindow width="400" height="200">
<comment>
main content
</comment>
<column color="darkGrey">
<row>
<button color="get'myColor'">
<label>
button one
</label>
</button>
<button color="use'myColor'">
<label>
button two
</label>
</button>
</row>
</column>
</floatingWindow>
</procedure>

</metaMel>

RedNine
11-16-2012, 07:00 AM
If you want to take a look at a fully fledged Python MetaData api then it might be worth downloading my Red9 Studio Pack. I've spent a long time writing a metadata setup and api for setting up and traversing data similarly to Bungie's setup. There's examples of how to add the hooks to rigs, how to walk the metaData network and this is expanding day by day. At the moment there's no UI for this, but the code is dead easy to implement and in the example I show how to hook the Morpheus rig up.

v1.27 has had a huge update and will be released early next week ;)

Red

CaptainSam
11-17-2012, 12:13 PM
So here's the initial challenge that I'm setting myself. I want to interpret this xml into a fully-functioning mel file that creates a floating, resizeable window with two buttons. The buttons' colors will be set with a modal window described in a mel file. The get'...' method will set the variable, and the use'...' method will re-use it.

So what you;re trying to do is basically what PyQt with Qt Designer gives you for free. Sorry to say this, but this looks like a huge waste of time. At least write this in Python (you can write Python for years and never touch object oriented programming if you insist on doing it the hard way).

Ive written tons of Mel guis over the years, including windows that build their content automatically based on lists of stuff. Ive deleted all that code by now, it only exists deep down in my Subversion history. These days, I use PySide/PyQt even for the simplest guis inside Maya and Nuke.

EdtheHobbit
11-17-2012, 04:04 PM
So what you;re trying to do is basically what PyQt with Qt Designer gives you for free. Sorry to say this, but this looks like a huge waste of time. At least write this in Python (you can write Python for years and never touch object oriented programming if you insist on doing it the hard way).

Well, I guess it's a good thing that I'm the one wasting my time! You're welcome to ignore me forever if that's your choice. Not one whit or tittle of your time will be wasted. I guarantee it.

Ive written tons of Mel guis over the years, including windows that build their content automatically based on lists of stuff. Ive deleted all that code by now, it only exists deep down in my Subversion history. These days, I use PySide/PyQt even for the simplest guis inside Maya and Nuke.

And any person who wants to use your simple guis would have to have PySide or PyQt with QT installed, correct? So students without admin access would be out of luck. I know I have a narrow view, but that's the market I'm catering to.

Look, guys. I'm just trying to challenge myself with a task that I think would be useful and educational. I'm not a TD, I'm not even really a programmer. I don't do this kind of work professionally, so I have the luxury to look for depth instead of efficiency. I'm doing things the hard way so that I know that I CAN.

EdtheHobbit
11-17-2012, 04:11 PM
I'm currently stuck on the same idea, how to implement meta-data in MEL. Specifically following this technical artist from Bungie. (http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=0CFMQFjAD&url=http%3A%2F%2Fwww.gdcvault.com%2Fplay%2F1708%2FModular_Procedural_Rigging&ei=HE-lUNSqDKL7iwLJlIGgCw&usg=AFQjCNEV553-fwKs0wwjKbi7szbC46OnJw&sig2=jcHBcUfsu_pm-Uftz4AXKA&cad=rja) Interestingly, this was presented in 2009, so only 3 years ago, and is entirely in MEL.

If you want to take a look at a fully fledged Python MetaData api then it might be worth downloading my Red9 Studio Pack.

thanks, Stoehr and Red! That's definitely food for thought... I'm lacking a LOT on the theory side, though. The more I dig into this, the more I realize how much I don't know.

I'm starting simple for now with very basic text replacement, but this is definitely the kind of direction that I want to be going.

ldunham1
11-18-2012, 12:35 AM
Ah I wouldn't take it personally, I dont think anyone's doubting abilities, I think its more to do with understanding your choices. I understand your reasoning, as - I'm sure - the others do. I think the objections to using mel, was that you intend it to eventually be used by others as something to extend their own work upon.I'm hoping that the final, final product of all this will be a way for amateurs, students, and small studios to set up pipeline tools capable of being customized down to variable names. The user only has to set up the initial conditions, and the metaPipe will take care of the rest. My thinking is that the final product, as fantastically useful as it might be, will - in comparison - be limited and hindered.
Either way, good luck, and I'll be interested in following this project's development :)

haggi
11-18-2012, 11:14 AM
Mel is only good for shelves and AETemplates now.
+1 for python

Even for AETemplates I only use python with pymel, its much more efficient.

EdtheHobbit
11-18-2012, 03:05 PM
As an aside, can anyone recommend a good resource for using Python with the API? I'd like to get into some real plugin programming at some point, but I'm still reeling from my last attempt at C++. Baby steps and all that.

giordi
11-19-2012, 11:23 AM
As an aside, can anyone recommend a good resource for using Python with the API? I'd like to get into some real plugin programming at some point, but I'm still reeling from my last attempt at C++. Baby steps and all that.
http://www.amazon.com/Maya-Python-Games-Film-Reference/dp/0123785782

EdtheHobbit
11-19-2012, 03:42 PM
Starting off, I need a way to source in scripts that will be located in sub-directories. This script returns an array of all files with a given extension type in my "metaMel" folder:


global proc string[] mmel.getFiles(string $fileType){

// * get the local script directory (linux)

string $scriptLoc = `internalVar -usd`;
string $userLoc = ($scriptLoc + "metaMel/");

// * initial variables

string $dirList[];
string $fileList[]; // <- This will be the return

string $files[] = (`getFileList -fld $userLoc`);

// * test conditions for ending directory search

int $end = 0;
int $whileCheck = 0;

// * loop to find all sub-directories

while(!$end){
for($file in $files){

// * check for directory status

if(`filetest -d ($userLoc + $file + "/")`){
$end = 0;
$dirList[size($dirList)] = ($userLoc + $file + "/");
}
}
$userLoc = ($dirList[$whileCheck]);
$files = (`getFileList -fld $userLoc`);
if($whileCheck == (size($dirList) - 1)) $end = 1;
$whileCheck++;
}

// * loop to get all .ext files

for($dir in $dirList){
string $dirFiles[] = `getFileList -fld $dir -fs ("*." + $fileType)`;
for($file in $dirFiles){
$fileList[size($fileList)] = ($dir + $file);
}
}

return $fileList;
}


And this will run a source command for each .mel file that is returned in this way:


//=================
// Source all .mel files in the metaMel directory
//=================

global proc mmel.metaSource(){
string $melFiles[] = `mmel.getFiles "mel"`;
for($file in $melFiles){
string $sourceCommand = ("source \"" + $file + "\"");
evalEcho $sourceCommand;
}
}

EdtheHobbit
11-30-2012, 10:08 PM
//=================
// Read File To Single String, given filePath
//=================
global proc string mmel.lib.readFileToString(string $filePath){
string $stringArray[] = `mmel.lib.readFileToStringArray $filePath`;
string $stringReturn = `stringArrayToString $stringArray "\n"`;
return $stringReturn;
}


calls mmel.lib.readFileToStringArray:



//=================
// Read File To String Array, given filePath
//=================
global proc string[] mmel.lib.readFileToStringArray(string $filePath){
int $fileId = `fopen $filePath "r"`;
string $lineArray[];
string $nextLine = `fgetline $fileId`;
while (size($nextLine) > 0) {
string $cleanLine = strip($nextLine);
$lineArray[size($lineArray)] = $cleanLine;
$nextLine = `fgetline $fileId`;
}
fclose $fileId;
return $lineArray ;
}



Next step, find and replace keywords

EdtheHobbit
01-19-2013, 10:10 PM
I've been working on building a new website, and I've been using a CSS compiling language called "LESS" (http://lesscss.org/) -- it simplifies and extends CSS in some pretty cool ways, but when it reaches your site, it's plain old CSS code.

It's very similar to what I want to do with metaMel - incorporating elements like mixins and variable-variables.

I haven't had any chance to work on metaMel lately, but I'm learning more python (for Houdini, now...) I'm looking forward to leveraging python for a lot of the string parsing stuff

EdtheHobbit
04-18-2013, 06:51 PM
Thought I'd drop by for an update - I actually got pretty darn far with metaMel.

I was able to write a really simple json file, parse it with Python, throw it to the mel-based interpreter, and build nicely-commented procedures for tasks in Maya.

Most of the new development was for the feature film "Free Birds" at RFX, so unfortunately I won't be able to share it.

Almost all of my work right now is Python for NUKE - and I'll be moving to Houdini in a few months, so my time with MEL is pretty much at an end. If I start working on personal projects again, I'll have to break out the dollar-signs and brackets again, but not for a while!

giordi
04-18-2013, 07:39 PM
Thought I'd drop by for an update - I actually got pretty darn far with metaMel.

I was able to write a really simple json file, parse it with Python, throw it to the mel-based interpreter, and build nicely-commented procedures for tasks in Maya.

Most of the new development was for the feature film "Free Birds" at RFX, so unfortunately I won't be able to share it.

Almost all of my work right now is Python for NUKE - and I'll be moving to Houdini in a few months, so my time with MEL is pretty much at an end. If I start working on personal projects again, I'll have to break out the dollar-signs and brackets again, but not for a while!

hei man just a question , if you use python for other software is still worth for you to go back to mel? I mean i jumped on houdiny latelty and i could resue all my pyqt ui and custom widget without need to blink :beer:

ldunham1
04-18-2013, 07:47 PM
cheers for keeping us in the loop! :)