Home Technical Talk

MEL Quick Export Script - Illegal Operations Ahoy!

Good afternoon everyone!

I'm trying to make a quick exporter, but I'm having a bit of difficulty...
//Grab a list of everything selected
string $lsS[] = `ls -sl`;
//Loop through the list and export selected
for ($i = 0; $i < `size ($lsS)`; $i ++)
{
	//Remove organization suffix
	string $filename = ("/data/forUnity" + 	substituteAllString ($lsS(i), "_lo", "");
	//Select object to be exported
	select $i;
	//Export FBX using required settings
	file -op "groups=0;ptgroups=0;materials=0;smoothing=1;normals=1" -typ "FBX export" -es "$filename";
}

From my troubleshooting, I can tell that my issue begins just inside the for loop when I'm trying to concatenate the string array, which is an illegal operation. Is there any way I can convert the information from the string array into a regular string so I can concatenate it properly?

Replies

  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Fixed up code:
    //Grab a list of everything selected
    string $lsS[] = `ls -sl`;
    //Loop through the list and export selected
    for ($i = 0; $i < `size ($lsS)`; $i ++)
    {
    	//Get current workspace and makeDir. 
    	string $ws = `workspace -q -rd`;
    	sysFile -makeDir ($ws + "data/forUnity/");
    	//Remove organization suffix
    	string $filename = $ws + "data/forUnity/" + substituteAllString($lsS[$i], "_lo", "") + ".fbx";
    	//Select object to be exported
        select $lsS[$i];
    	//Export FBX using required settings
    	file -op "groups=0;ptgroups=0;materials=0;smoothing=1;normals=1" -typ "FBX export" -es $filename;
    }
    

    To access an array you need to do $arrayVar[$variable] you had it as $lsS(i). Another thing is when you select you are select a number instead of the object. Another thing is for -es flag you are not passing the variable $filename but the string $filename. Hope that helps. Sorry my mel is rusty
  • Dan Allardyce
    Thank you! That'll really speed up my exporting.
Sign In or Register to comment.