Home Technical Talk

Renaming Maya Materials with special characters

polycounter lvl 11
Offline / Send Message
raul polycounter lvl 11
Hello,

I was trying to rename materials with specific characters, but everytime i do that maya will change the letter to an underscore.  For example i need to be able to use "materials/mycoolmaterial_01/surf_01", maya will rename it to "materials_mycoolmaterial_01_surf_01". 

My way around it is by opening the obj with notepad and changing the names by hand. Which can be tedious and time consuming. So i was wondering if anyone has suggestions.  I was considering making a batch command so that after it exports the obj it looks at the obj and renames the stuff properly. But im unsure how to even start that start that, as my scripting abilities only go so far..

Any tips or help is appreciated it! :)

Replies

  • throttlekitty
    Options
    Offline / Send Message
    You could use some search&replace magic in Notepad++. By plain text, you could simply mass replace "materials_mycoolmaterial_" with "materials/mycoolmaterial/" which would leave "surf_01" untouched. Or, not have space/underscore in the material names if possible and do a simple replacement of "_" with "/".

    Alternatively, I think we could write a regular expression that could replace only the first 2 underscores in a line. I'm not a regexp guru, so I'm not sure how to write a catch-all that could identify which underscore(s) are part of a filename if they are more than two folders deep.
  • kwyjibo
    Options
    Offline / Send Message
    kwyjibo polycounter lvl 7
    Is the obj the file format used by the game? If there's an additional conversion tool involved maybe you could add some code there to replace say a "_slash_" with "/" on import. 
  • raul
    Options
    Offline / Send Message
    raul polycounter lvl 11
    Thanks guys i had a friend show me how to do a quick app that handles that in visual studio, and it worked! Because maya wont let us use any other character other than "/" and some of the material names need to have "_", "wood_01" .   We ended up using double "_"  then used RegEx to find "usemtl" line in the obj. file to replacse the "__" with "/"

    From that, it led me to try out system commands within maya. And man, its open a door of opportunites for me, hehe. However i wanted to use the command "Move"  but maya spits out the error  "

    The system cannot find the path specified"

    when i try to do
    system("move C:/batchTest/pew.obj C:/batchTest/POW.obj");

    I used the same line with a .bat file and it worked fine. Anyone knows why that happens?


  • sprunghunt
    Options
    Offline / Send Message
    sprunghunt polycounter
    raul said:
    Thanks guys i had a friend show me how to do a quick app that handles that in visual studio, and it worked! Because maya wont let us use any other character other than "/" and some of the material names need to have "_", "wood_01" .   We ended up using double "_"  then used RegEx to find "usemtl" line in the obj. file to replacse the "__" with "/"

    From that, it led me to try out system commands within maya. And man, its open a door of opportunites for me, hehe. However i wanted to use the command "Move"  but maya spits out the error  "

    The system cannot find the path specified"

    when i try to do
    system("move C:/batchTest/pew.obj C:/batchTest/POW.obj");

    I used the same line with a .bat file and it worked fine. Anyone knows why that happens?


    if you want to move a file around from within maya you can use the sysFile command. 

    http://help.autodesk.com/cloudhelp/2015/CHS/Maya-Tech-Docs/Commands/sysFile.html

    so you would use the -rename flag with sysFile - eg: 

    sysFile -rename "C:/batchTest/pew.obj" "C:/batchTest/POW.obj";
    
    //This renames pew.obj to POW.obj
  • raul
    Options
    Offline / Send Message
    raul polycounter lvl 11
    Thank you all so much for the wonderful help! I learned a ton doing this small project. I realized i never said what this was for. Turok Dinosaur Hunter was released in Steam a year ago, and last month the editor was released! Seeing that this was one of my childhood fav, i wanted to make something for it now that i sorta know what im doing. Except that its very difficult to be able to export assets from maya, since the editor is not exactly up to modern standards.

    Anyway, thanks again to everyone! I havent properly finished getting ready the tools for people to use yet, but i thought id post my "exporter script" in case it helps others. Soon i will post the entire thing in my website as there is a seperate app to rename the materials with regex.

    //Turok Super Hacky exporter. Maya saves out the materials with bad names and is a bitch to rename them by hand as well as move the files
    //This script in combination with another app take care of all those headaches and send the files where turok is installed.
    //Raul Aparicio 2017
    
    //Gather scene information string $currentFullSceneName = `file -q -sceneName`; string $sceneSaveName = substituteAllString($currentFullSceneName,"/","\\"); string $sceneLocation = `match "^.*/" $currentFullSceneName`; string $exportType = ".obj"; string $mat = ".mtl"; string $locationOfTurokConverter = "S:/TurokModding/game/models/TurokConverter.exe"; // will be an input string $locationOfTurokGameToSaveFiles = "P:/SteamLibrary/steamapps/common/Turok - Dinosaur Hunter/temp/"; //will be an input
    //Get the name of the selected object string $currentSelection[] = `ls -sl`;
    string $finalDestination = $sceneLocation;
    //Export OBJ if ($exportType == ".obj"){ for ($obj in $currentSelection) { //Export obj with options file -force -options "groups=1;ptgroups=1;materials=1;smoothing=1;normals=1;" -typ "OBJexport" -pr -es ($sceneLocation + $obj + $exportType); //Run the magic material fixer by Nick system("start " + $locationOfTurokConverter + " " + ($sceneLocation + $obj + $exportType)); //Move the created files to the game location sysFile -copy ($locationOfTurokGameToSaveFiles + $obj + $exportType)($sceneLocation + $obj + "_export"+ $exportType); sysFile -copy ($locationOfTurokGameToSaveFiles + $obj + $mat)($sceneLocation + $obj + "_export"+ $mat); //Create a copy of the mtl with the node.. sysFile -copy ($locationOfTurokGameToSaveFiles + $obj +".obj"+ $obj +$mat)($sceneLocation + $obj + "_export"+ $mat); //When this is all done lets delete the obj from the folders to prevent nicks tool from crashing //The clean ones.. //sysFile -delete ($sceneLocation + $obj + "_export"+ $exportType); //sysFile -delete ($sceneLocation + $obj + "_export"+ $mat); //The originals.. //sysFile -delete ($sceneLocation + $obj + $exportType); //sysFile -delete ($sceneLocation + $obj + $mat); //Copy the command and the name of the exported obj to paste on the console system("echo convertObj temp\\" + $obj + ".obj | Clip"); } }
    print ( "export done!!")



Sign In or Register to comment.