PDA

View Full Version : Export Selected with name increment


hypnocookie
02-24-2011, 11:05 AM
Hi all. I am brand new to mel scripting and want to write a simple script to select a specific group and export the selected object as a given name with an incremented number on the end.
i.e.
objectExport_0001.mb
objectExport_0002.mb
etc...

so far I have coiped the script editor and can have it copy the correct group and over write any given name by defining a specific name like so:

p, li { white-space: pre-wrap; } select -r topGroup;
file -force -options "v=0" -typ "mayaBinary" -es "c:/........./scenes/objectExport_0001.mb";
select -cl;


but this over writes the 0001 file every time.


Cheers for your help.

thematt
02-24-2011, 07:45 PM
well you have to loop through your selection and import each object separetaly

something like that..sorry not maya at home so


{
//get your selection
string $sel[]=`ls -fl -sl`;
int $i;

//loop through it using the increment number
for ($i=0;$i<`size $sel`;$i++)
{
//export while adding the number
file -force -options "v=0" -typ "mayaBinary" -es ("objectExport_"+$i+".mb");
}}

hope it helps

cheers

hypnocookie
02-25-2011, 09:03 AM
Hmm, nearly there I think, at the moment it just exports the selection as
objectExport_0.mb

and over writes that file everytime. unless I am doing something wrong.

thematt
02-25-2011, 10:30 AM
sorry wrote that really fast without testing it

it will be more like that

first select all you obj and run the script


{
//get your selection
string $sel[]=`ls -fl -sl`;
select -cl;
int $i;
//loop through it using the increment number
for ($i=0;$i<`size $sel`;$i++)
{
//export while adding the number
select $sel[$i];
file -force -options "v=0" -typ "mayaBinary" -es ("c:/temp/objectExport_"+$i+".mb");
}}




cheers

jaydru
02-25-2011, 01:08 PM
//get your selection
string $sel[]=`ls -sl`;
$count = size($sel);
$bufferSize = (size(string($count)));
//loop through it using the increment number
for ($i=0; $i<size($sel); $i++)
{
string $buffer = "";
for ($j=0; $j< ($bufferSize - size(string($i +1))); $j++)
$buffer = ($buffer + "0");
//export while adding the number
select $sel[$i];
file -force -options "v=0" -typ "mayaBinary" -es ("c:/temp/objectExport_" + $buffer + ($i +1) +".mb");
}


i modded that slightly so that it give a buffer ie file_001 file_010 file_100 so that windows will list them nicely

CGTalk Moderation
02-25-2011, 01:08 PM
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.