Home Unreal Engine

Mel Scripting

passerby
polycounter lvl 12
Offline / Send Message
passerby polycounter lvl 12
Wondering if it is possible to make a mel script that exports the contents of your different view layers off as different files into the same directory as the MB file, with pre-set options.


what im trying to do is make something i can put in my shelf that will let me export out my High Poly, Low Poly and Cage in one click in the SBM format so i can quickly get things into xnormal.

EDIT: and i was in the wrong forum, can a mod move this up a level to Technical Talk

Replies

  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Definitely possible.
    string $layers[] = `ls -type displayLayer`;
    for ($layer in $layers){
        if ($layer != "defaultLayer"){
            //Set all layers to off then turn the current layer on. 
            setLayerTo all".visibility" 0;
            setAttr ($layer+".visibility") 1;
            //Grab connections of the layer
            $conns = `listConnections -destination 1 -source 0 ($layer+".drawInfo")`;
            select $conns;
            //do export stuff
        }
    }
    
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    ah nice, so i can just get all the export stuff from watching the console as i do a export, and maybe replace the name with the layer name variable.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    passerby wrote: »
    ah nice, so i can just get all the export stuff from watching the console as i do a export, and maybe replace the name with the layer name variable.

    Yup. I didnt have xnormal installed but you should be able to copy what the log spits out and replace the path (look into the file command. Believe you can query the scene name and do some string manipulation) and append the layer name.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    Yup. I didnt have xnormal installed but you should be able to copy what the log spits out and replace the path (look into the file command. Believe you can query the scene name and do some string manipulation) and append the layer name.

    sweet will let you know how it goes when i get home later tonight, this should drastically speed up work flow way better than haveing ot manaully export out 3 files every-time i fucking make a small change and i already use the view layers to organize this stuff anyways.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    thanks got the export commend in there.
    string $layers[] = `ls -type displayLayer`;
    for ($layer in $layers){
        if ($layer != "defaultLayer"){
            //Set all layers to off then turn the current layer on. 
            setLayerTo all".visibility" 0;
            setAttr ($layer+".visibility") 1;
            //Grab connections of the layer
            $conns = `listConnections -destination 1 -source 0 ($layer+".drawInfo")`;
            select $conns;
            //do export stuff
            file -force -options "-ExportNormals true -SmoothNormals false -ExportUVs true -ExportTB true -ExportVCols false " -typ "xNormalSBMTranslator" -pr -es "C:/Users/Chris/Desktop/test.SBM";
        }
    }
    

    so how would i grab the path the project MB file is stored in and use it in that string, and use the MB's files name with the layer name appended?
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    file -q -sceneName
    

    That will give you the current project the file is stored in. My plan would be to take that, remove the / pop off the last index of the array and construct back again. Then add $layer back and append the extensions as a string. Probably a better way to do this but dont have maya right now. Always sucked at string manipulation XD
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    thanks will try that out when i get home.

    sorry for being so stupid when it comes to scripting.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    No problem. Hopefully when I get home will work something up.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    k this is what got
    string $layers[] = `ls -type displayLayer`;
    for ($layer in $layers){
        if ($layer != "defaultLayer"){
            //Set all layers to off then turn the current layer on. 
            setLayerTo all".visibility" 0;
            setAttr ($layer+".visibility") 1;
            //Grab connections of the layer
            $conns = `listConnections -destination 1 -source 0 ($layer+".drawInfo")`;
            select $conns;
            //do export stuff
            string $exportname =`file -q -sceneName` + "_" + $layer;
            file -force -options "-ExportNormals true -SmoothNormals false -ExportUVs true -ExportTB true -ExportVCols false " -typ "xNormalSBMTranslator" -pr -es $exportname;
        }
    }
    

    now i just need to know how to back off the .mb of file -q -sceneName commnd and it would be nice if i could add /export in the string so it puts these exported files in a subfolder called export next to the scene file.

    any ideas.

    would also like to find a way to make it olny work on layers with a certain prefix kinda like vtools in PS so say i have "~highpoly", it would export that layer, but if it was just "highpoly" it would be ignored.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    string $layers[] = `ls -type displayLayer`;
    string $extension = ".SBM";
    for ($layer in $layers){
        if ($layer != "defaultLayer"){
            //Set all layers to off then turn the current layer on. 
            setLayerTo all".visibility" 0;
            setAttr ($layer+".visibility") 1;
            //Grab connections of the layer
            $conns = `listConnections -destination 1 -source 0 ($layer+".drawInfo")`;
            select $conns;
            //do export stuff
            string $sceneDirectory=`file -q -sceneName`;
            string $directory = `match "^.*/" $sceneDirectory`;
            //Interesting find. Can use dirname(scenepath) to get directory to avoid figuring out regular expressions.
            //Appending the Export Folder to the directory path.
            $directory = $directory + "Export/";
            //Make the export directory.
            sysFile -makeDir $directory;
            //Shortname gives you the scene name and extracts out .mb
            string $fileName = `file -q -sceneName -shortName`;
            $fileName = `match  "^[^\.]*" $fileName`;
            //Export 
            file -force -options "-ExportNormals true -SmoothNormals false -ExportUVs true -ExportTB true -ExportVCols false " -typ "xNormalSBMTranslator" -pr -es ($directory + $fileName+ "_" + $layer +$extension);
        }
    }
    

    Should be all except that ~layerName stuff. I got this working with obj and just put in the stuff for Xnormal from what you posted, let me know if it works.

    Hmm just tried doing the delimiter thing and for some reason cant cast startsWith into an int.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    thanks that is excellent, works exactly how i want, just replaced the last commnad to the one o was useing for sbm export, than added a setLayerTo all".visibility" 1; at the very end to re-show all layers.

    thanks alot for this.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Ah no problem. Learned couple of new commands, gonna try and do this delimiter thing. Odd not working.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    ya thanks i really need to take the time to learn some scripting at somepoint, since it would help me build a nicer workflow and tools to use in maya, and allow me to do more with UDK, and hell mel syntax seems similar to php in a way which also i should pick up at sometime.
Sign In or Register to comment.