Using MEL to change mutilple MA files in a directory

Become a member of the CGSociety

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

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 07 July 2013   #1
Using MEL to change mutilple MA files in a directory

I'm a rather novice programmer when it comes to MEL, so any help on this would be appreciated.

- I have a massive directory of asset folders (200+) and I need to open up each master file (ex. bucket_master.ma) which is contained in its own folder (ex. bucket) and run a script that will group, geo, clean up the file, change settings, etc. etc. I already have the clean up script completed. I just need to run it on the 200+ asset master files.

- I need to specify a top folder (ex. C:\project\props\) and then have the script search the subfolders within that (ex. C:\project\props\bucket) and find the _master.ma file, run the clean up script and move on to the next one.

- I've been looking up scripts on how to do this, but so far I've been unable to find one that seems to be fully automated. The one I tried previously requires all the master files to be in the same folder.

Any help would be appreciated?
 
Old 07 July 2013   #2
Additionally, so far I've tried creating a for loop for opening the files but it only seems to be opening just the first file in the string list

string $masterList[]=`getFileList -folder "Z:\\Projects\\props\\cakeCover\\" -filespec "*_master.ma"`;
for($i=0; $i<size($masterList); $i++)
{

file -type "mayaAscii" -open -f $masterList[$i];

// rest of the script //

};

There are three _master.ma files in that folder and they're being passed to $masterList just fine but its not running the script on the other _master files in the list.
 
Old 07 July 2013   #3
If you take a look at the contents of $masterList, it only contains the filename, not the full path. You need to reconstruct the path prior to the file open call otherwise you will get a file not found error.

e.g.
string $masterList[]=`getFileList -folder "Y:\\test\\" -filespec "*_master.ma"`;
for($i=0; $i<size($masterList); $i++)
{
    string $filePath = "Y:\\test\\" + $masterList[$i];
    file -type "mayaAscii" -open -f $filePath;

    // rest of the script //
    print($masterList[$i] + "\n");

};

-ChrisZ
 
Old 07 July 2013   #4
I tried to changes, but its still not opening the other files in the folder and running the script, it will only still work for the first one.
 
Old 07 July 2013   #5
Are there any errors in your script editor? If your current cleanup script code throws an error, it will end the execution of the whole script. If you remove your cleanup script code and replace it with only a print statement, do all files open? (See my previous example)

-ChrisZ
 
Old 07 July 2013   #6
Here is a mel snippet i use for exactly this issue

string $stringArray[] = stringToStringArray((`fileDialog -m 0`),"/");
$stringArray = `stringArrayRemove {$stringArray[(size($stringArray) - 1)]} $stringArray`;
string $dir = `stringArrayToString $stringArray "/"` + "/";
string $fileList[] = `getFileList -folder $dir -filespec "*.m?"`;

for($i=0;$i<`size $fileList`;$i++)
{
	print($i + " / " + `size $fileList` + "\n");
	file -f -typ "mayaAscii" -o ($dir + $fileList[$i]);
//  file -f -typ "mayaBinary" -o ($dir + $fileList[$i])
	print($fileList[$i] + "\n");
//scene edit code start---------------------------------------------------------





//scene edit code end---------------------------------------------------------
	file -save;
};
 
Old 07 July 2013   #7
After doing some trouble shooting I've found that the for loops I have within the script are causing the problem. Its still completing the script mind you but only for the first file in the list. I commented out all three for loops and it cycled and saved all the files in the list like it was supposed to.

Here's an example of the for loop, when I comment it out, the whole thing works, but when I uncomment it, it only does the first file.

string $hpGeo[] = `ls "*_hp"`;
for ($i = 0; $i < size($hpGeo); $i++)
{
setAttr ($hpGeo[$i] + ".visibility") 0;
}

// rest of script //
 
Old 07 July 2013   #8
Originally Posted by Vintango24: After doing some trouble shooting I've found that the for loops I have within the script are causing the problem. Its still completing the script mind you but only for the first file in the list. I commented out all three for loops and it cycled and saved all the files in the list like it was supposed to.

Here's an example of the for loop, when I comment it out, the whole thing works, but when I uncomment it, it only does the first file.

string $hpGeo[] = `ls "*_hp"`;
for ($i = 0; $i < size($hpGeo); $i++)
{
setAttr ($hpGeo[$i] + ".visibility") 0;
}

// rest of script //

Is it possible that one of the nodes in your list (that ends in _hp) doesn't have a visibility attribute (e.g. a material)? This would cause the script to fail. Although, there should be an error in the script editor (unless you are silently catching it).

Print out the contents of your hpGeo list and see if there are any nodes that don't belong.

-ChrisZ
 
Old 07 July 2013   #9
That's the thing, I'm not getting any syntax errors or anything of the like. And the only thing in the hp group are 3 pieces of geo that are under the naming convention. I'm going to see if anything pops up error wise when I echo all Commands.
 
Old 07 July 2013   #10
I figured it out. I was using the same $i integer for the for loops contained within, when I changed it to $f it looped through all the files and performed the for loop. Now all I need is to get it to batch change all the _master files contained within sub folders within the original target folder, any ideas?
 
Old 07 July 2013   #11
Hi,
I've just posted on another post a solution to edit multiple files : http://forums.cgsociety.org/showthr...?f=89&t=1115240

It edits maya scenes in batch mode. You just have to put a condition in the mel file to execute your cleaning procedure if only the scene name has "_master"

hope it could be useful to you
__________________
DrWeeny
My Blog
My Vimeo
LinkedIn
 
Old 07 July 2013   #12
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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 03:00 PM.


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