Use Maya plugins with Mel (and Python)

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 03 March 2008   #1
Use Maya plugins with Mel (and Python)

Hi people,

I have a large amount of Collada meshes to convert to ".egg" (Panda3D format). As there is no converter Collada->egg, I use Maya to import the meshes with ColladaMaya (Feeling Software plugin) and then export them with a tool provided with Panda (maya2egg).

If I do these 2 steps manually, there is no problem, but I have more thant 200 meshes to convert and more coming. So I want to create a Python script which will take a directory and apply these steps to each mesh in this directory :
1) import the Collada mesh in Maya using ColladaMaya plugin and MEL
2) save the imported model in ".mb"
3) call maya2egg on the result of the second step

I have no problem for the steps 2 and 3. But I don't find how to do the first step.
I can use any MEL command from Python with the maya module but I don't see how to use an importer plugin.

Does anybody have an idea of the way to do this ?

Old 03 March 2008   #2
maybe try using the maya.mel module and run the plugin command through there?

also, it seems like the only thing you need python for is an easy way to get a directory listing? so why don't you do the whole thing in mel, and call os.listDir just to get the list of egg files you want to convert?
Old 03 March 2008   #3
Hi Benjamin,

well I'm not so good with python yet...
so here goes a mel version to do it...

tools used...
collada for maya from here... -->
panda 3d version 1.4.2 from here... -->

this script only use the model export command to egg...

also I have added some folder creations to the script... just change these folder names to whatever you use...
I have added a Done folder... just if Maya should crash so you can keep an eye on how far you have gotten...
what the script does is moving the done files to that folder...
so next time you run the script it doesn't take those files once more...

I'm not sure how many file "openings"/conversions Maya can handle at the moment... or if Autodesk has fixed the
memory error problem... back in 2004/2005 when working at Captain Scarlet on a autobeavering script ... for maya to lightwave conversion...
with Maya 5.5 it could handle arround 19-22 scene files before the memory error happend...
and maya and the script had to be started again...
Maya 6 could handle between 24-27 files before the error happend...

hope you use some of it...

kind regards


proc daAutoCollada2EggThingie() { //checking if the collada plugin is loaded... checkIfColladaPlugIsLoaded; //check if the folders exist... checkIfDaColAndEggFoldersExist; //do the collada files to egg process... daColladaFilesToEggProcess; } //the folder where the Collada files are... //just change the foldername here if you want it at a different place... :-) proc string daColladaFileFolder() { return "c:/colladaTestFolder/collada_files/"; } //the folder to move the done collada and Maya mb files to... proc string daDoneColladaFileFolder() { return "c:/colladaTestFolder/done_collada_files/"; } //the folder to put the egg files into... proc string daEggFileFolder() { return "c:/colladaTestFolder/egg_files/"; } proc checkIfDaColAndEggFoldersExist() { string $daFolders[] = {`daDoneColladaFileFolder`, `daEggFileFolder`}; for($i = 0; $i < size($daFolders); $i++) { //checking if the folder exist... if(!`file -q -ex $daFolders[$i]`) { //if not create it... sysFile -md $daFolders[$i]; } } } proc daColladaFilesToEggProcess() { string $daColFileFolder = `daColladaFileFolder`; string $daDoneCFFolder = `daDoneColladaFileFolder`; string $daEggFFolder = `daEggFileFolder`; string $daColFiles[] = getDaColladaFilesFromDaFolder($daColFileFolder); int $daNumberOfFiles = size($daColFiles); string $daExt = ""; string $daColFileName = ""; string $daFileAndExtBuffer[]; for($i = 0; $i < $daNumberOfFiles; $i++) { //create a new scene file... file -f -new; //tokenize to get filename and collada file extension... tokenize $daColFiles[$i] "." $daFileAndExtBuffer; $daExt = $daFileAndExtBuffer[size($daFileAndExtBuffer)-1]; $daColFileName = $daFileAndExtBuffer[0]; //collada file import command string... $daColImportCmd = "file -import -type \"COLLADA importer\" -rpr \""+$daColFileName+"\" \""+($daColFileFolder+$daColFiles[$i])+"\""; eval($daColImportCmd); //save scenefile in Mb format based on filename... file -rename ($daColFileFolder+$daColFileName); file -f -save -type "mayaBinary"; //calling the maya2egg process... doDaCol2EggThingie($daColFileName, $daEggFFolder, $daColFileFolder); //move the collada and maya file to the done folder process... moveDaColFilesToDoneFolder($daColFileFolder, $daColFileName,$daDoneCFFolder,$daExt); } //create a new scenefile... file -f -new; print("the Collada files to Panda 3d Egg format is done... :-)"); } proc doDaCol2EggThingie(string $daColFile, string $daEggFolder, string $daColFFolder) { //some of the stuff in this proc is taken from the MayaPandaTool that ships with panda3d... //located in the panda3d plugin folder... string $daMV = substituteAllString(`about -v`, ".", ""); $daMV = substituteAllString($daMV, "0", ""); string $daEggArg = ("maya2egg"+$daMV); string $pandaEnvSetup = "set PATH=%MAYA_LOCATION%\\bin;%PATH% & "; string $daEggFileName = $daColFile+".egg"; string $daMbFile = $daColFFolder+$daColFile+".mb"; string $daEggCmd = ($daEggArg+" -a model"); string $daEggFile = ($daEggFolder+$daEggFileName); system($pandaEnvSetup+$daEggCmd+" -o "+"\""+$daEggFile+"\""+" "+"\""+$daMbFile+"\""); } proc moveDaColFilesToDoneFolder(string $daFileFolder, string $daFileName, string $daMoveFolder, string $daExtension) { string $daMoveFile = ""; string $daMovingTo = ""; string $daMFs[] = {($daFileName+"."+$daExtension), ($daFileName+".mb")}; for($i = 0; $i < size($daMFs); $i++) { $daMoveFile = ("\""+$daFileFolder+$daMFs[$i]+"\""); $daMovingTo = ("\""+$daMoveFolder+$daMFs[$i]+"\""); if(!`file -q -ex $daMoveFile`) { string $daMoveFileCmd = "sysFile -move "+$daMovingTo+" "+$daMoveFile; eval($daMoveFileCmd); } } } proc string[] getDaColladaFilesFromDaFolder(string $daFolder) { string $daFileList[]; string $daDaeFileList[]; string $daXmlFileList[]; //get the collada Dae files from the folder... $daDaeFileList = `getFileList -fld $daFolder -fs "*.dae"`; //get the collada XMl files from the folder... $daXmlFileList = `getFileList -fld $daFolder -fs "*.xml"`; //put them together... $daFileList = stringArrayCatenate($daDaeFileList, $daXmlFileList); //and sort them... $daFileList = sort($daFileList); //return the collada file list from the folder... return $daFileList; } proc checkIfColladaPlugIsLoaded() { //Maya installation location... string $daMAD = `getenv "MAYA_LOCATION"`; //maya plugin folder string $daMPD = $daMAD+"/bin/plug-ins/"; //the collada plug string $daCP = "COLLADA.mll"; //path to collada plug... string $daCPP = $daMPD+$daCP; //check if collada plugin exist... if(!`file -q -ex $daCPP`) { error "Collada plugin doesn't exist... \n"; } else { //is collada plugin loaded... if not load it... if(`pluginInfo -q -l $daCP` != 1) { catch(`loadPlugin $daCPP`); } } } daAutoCollada2EggThingie;
Alex V. U. Strarup
Mel script monkey
Facebook LinkedIn

one mistake can ruin it all... :)
Old 03 March 2008   #4
Thanks a lot for your answers ! Strarup you saved a week that could have been really "headaching" You might not be good at Python but you rocks at mel

For me, I'm using Python because it is the language we use at work. It is very powerful for scripting and OO Programming. And with the maya modules and the "mel.eval" functions, you can execute mel commands. So it is quite practical.
The best thing is that you can convert models without launching Maya. You just have to initialize Maya python module. So it all happens in the script and it can be used in any Python program.
Just to know because I'm curious : is it possible to execute mel script outside of the Maya GUI as in Python?

But to get back to my problem, I had 2 things missing that your wonderful script showed me :
1 - Loading the plugin if necessary (it can be useful )
2 - The line to import the file using the COLLADA importer type :
$daColImportCmd = "file -import -type \"COLLADA importer\" -rpr \""+$daColFileName+"\

And it's just for the parts I didn't find before. There are lot of things in your script that will be really helpful!

Also, I didn't know for the memory leak in Maya, it's good to know it exists. I'll quickly see with all the models I have to convert. I'll tell you the new range of handled scenes if the problem's still here.

So thanks again
Don't hesitate to PM me if you have Python questions, I'm not a Python expert (yet ) but I'd be glad to help.
Old 03 March 2008   #5
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:52 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.