User avatar
By deadalvs
this is cool.

we surely all know the problem, when we want to open a pc generated maya file on a mac, that the textures can not be found because the drive names are not equal on macs/pcs.

or You have a network drive renamed from U:/ to V:/ and would have to manually update every linked texture path to V:/../tex.pic

• T:/
• //macname/user/
and so on.

now i created a script that automates this and it works on a mac since the mac does not care for / or \ and reads them as the same. but i still have one problem with the pc.
the \ sign which often is used in network drive names is used in maya as an escape sequence like for example "\n" to go to a new line.

this happens in the scipt (in the last few lines) which gives an error. and i do not remember how this escape sequence could be broken so this script also works on pcs...

help from anyone ? :roll:

* * * ...
User avatar
By deadalvs
please report also other issues...

i hope i can resolve them...
User avatar
By DrMerman
Hey mate :)

I took a quick look at your script and came up with the following few tweaks to the global proc :
Code: Select all
global proc changePaths()
string $newPrefix = `textField -q -tx newPrefix`;

string $oldPrefix = `textField -q -tx oldPrefix`;
string $oldPrefix_errorFree;

//a string that when printed, results in \\
    string $theDoubleSlash = "\\\\";

//if we make a change, we need to keep track of it for when we search later
     int $didWeMakeTheChange = 0;

//turn the prefix into an array, and count the number of times a / appears
     string $oldPrefixCheck[] = stringToStringArray ($oldPrefix, ":");
     int $forwardSlashCount = size( $oldPrefixCheck );

//now use that number to alter the prefix as needed
      if ( $forwardSlashCount == 0 )
         //you have a prefix in the form d:\
         //so we change the d:\ to d:\\
              $oldPrefix_errorFree = `substitute $theDoubleSlash $oldPrefix $theDoubleSlash`;
         //then we record the change
              $didWeMakeTheChange = 1;

     //don't delete
     //get all of the file nodes
                select "file*";
                string $sel[] = `ls -sl`;
                //string $current;
//*** Is the following section used just to get the file node names? If so you could delete all within the ///////

///////////////////////////////////////////////you could delete this section

     //rename each file node to CHANGENAME1
                //for ($current in $sel)
                    //select $current;
                    //rename "CHANGENAME1";

     //Select all of the nodes called CHANGENAME*
                //select "CHANGENAME*";
                //string $sel[] = `ls -sl`;
                //string $current;

     //Rename each node to file1;
                //for ($current in $sel)
                   //select $current;
                   //rename "file1";

//////////////////////////////////////////end of section

     //don't delete
                int $texFileNumber = `size($sel)`;

     //for every node in the selection
                for ($a = 1; $a <= $texFileNumber; $a++)
		    //print ($a + "\n");
                    //print ($oldPath  + "\n");
	            //string $oldPrefix = "blaah";
	            //string $newPrefix = "//Dualpure/mousebat/";
	            //print ($newPath  + "\n");

                    //get the old path  - eg D:/MyFolder/myImageFile.png
	                  string $oldPath = getAttr ("file" + $a + ".fileTextureName");
	                  string $newPath;

	            //find out if we changed anything earlier
	                  //if we did, substitute in the $oldPrefix_errorFree value
                                  if ( $didWeMakeTheChange == 1 )
                                      print ("\nNow need to substitute in the oldPrefix_errorFree value, which is : " + $oldPrefix_errorFree);

	                  //else, substitute in the $oldPrefix value
                                  if ( $didWeMakeTheChange == 0 )
                                      print ("\nNow need to substitute in the oldPrefix value, which is : " + $oldPrefix);

                    //in the Attribute editor, assign the new image
	                  AEassignTextureCB  ("file" + $a +".fileTextureName") $newPath "image";

But thats still hit or miss. Maya tends to get confused when you start trying to get around the \ thing. So why not do something like the following :

NOTE : At the moment, the first box in your UI is not being used.
Code: Select all
global proc changePaths()
     string $fileNodes[] = `ls "file*"`;		      //gets all the file nodes
     string $currentFilePaths;					    //is the current file path
     string $removedStart;					           //is the current file node, with the first 3 characters removed
     string $toAdd = `textField -q -tx newPrefix`;		  //is the new prefix
     string $newPath;						     //is the new file path

for ($n=0; $n<size($fileNodes);$n++)

     if ($fileNodes[$n] != "")
	$currentFilePaths = eval ("getAttr " + $fileNodes[$n] + ".fileTextureName;");
	$removedStart = `substring $currentFilePaths 4 99999`;
	string $newPath = $toAdd + $removedStart;
	string $command = $fileNodes[$n] + ".fileTextureName";
	eval ("setAttr -type \"string\" " + $command + " \"" + $newPath + "\";");

It basically goes through all of the file nodes, and replaces the drive prefix with whatever is in your second textField.

Hope this helps :)

Dr Merman
User avatar
By deadalvs
thanks for the «update» !!

i'll try to work on on monday, after my landscape architecture diploma exam...

* * *

«i'll be back» ... :wink:
User avatar
By deadalvs
by the way... why i renamed the files in the script two times is because it can happen that the user deletes the first few files and adds other files. the new files are renamed «upwards», thus all the files are not anymore named on from file1, file2, file3, ...
i found it was the only way to completely rename them to sth other and rename them to file1, then, the numbers are correct to work with the for loop.
User avatar
By DrMerman
Ah, I see :) In my second proc, you get around that altogether by only referencing the array, and never the actual file node. Good luck with your exam, mate :D
User avatar
By deadalvs
ah yess, i really had no time to check yet exactly, but of course this makes sense ... "duh!"

thanks for the good wishes ! a little luck is always good... saved my butt multiple times... :lol:
User avatar
By deadalvs
ah, damn it ... :)

* * *

i took a couple of minutes and found what i've been searching for.

that escape sequence thing.

* * *

if i want to MEL to print out the sign of a quotation mark (") i have to type this:

print "\"";
//result: "

in this case, the backslash is used to «ignore» the effect of the following sign, the first ", which would terminate the string normally, while the second, which actually SHOULD terminate the string would cause an error.
the same could be used with our path-\ signs.

i had the error about the unfinished escape sequence. i should have been writing print ("\\" + "\\"); to get a single \\ (error in this sense of this example)

for the case of changing F:\ to J:\ ...
i'd have to filter out the all the \ out of the $oldPrefix and replace them later each by a "\\" (J:\\) resulting in the correct new path without coding error...

* * *

well, it's a bit chaotic, just wanted to mention it... g'd nite !
User avatar
By deadalvs
oh boy...

You're way ahead i see... :)

* * *

i've seen now that You were using all the points i mentioned already... well, maybe someone new to MEL can use it...

* * *

i tried a little more with the script and came to this version here: ...

it works perfectly by just using / instead of \ !! maya corrects the signs automatically.

actually i do want to be able to have editable prefixes, not just the first three signs, so i implemented the most useful of Your code... now it looks «pro» :)
i would have to scan out all \ signs and insert them as \\ for maya to work with it properly. but this gave me now a LOT of errors (even with the eval command), so i just tried the easy way - successful !

thanks for the cool tips again... !

* * *

i'm habby with the script now... !
User avatar
By DrMerman
Awesome mate :) Script's looking great. I take it all went well with the exam? :D
User avatar
By deadalvs
i think it went all right, thanks...

i always have this strange feeling after exams about my bad handwriting... i hope they can read it ... :oops:

* * *

actuall interesting themes [topic: landscape architecture]:

the love of geometry in baroque gardens

parks for the people; how private landscape gardens became available for the working class and about the integration of green spaces in industrialized cities
User avatar
By DrMerman
Well, rather you than me, mate :D Awesome that it went well though. And I'm exactly the same with handwriting. It's pretty much the smallest thing you'll ever be forced to read :)
By p3tamaxwell
I know nothing about scripting.... BUT... if instead of having a old path button and a new path button then what if you had a "ignore old path" check box... new path field just as you have now.

That way you can throw ALL your textures into one location and regardless of where the original material was looking for textures it would go to the new location and find them all based on looking for the file name. It may seem like a messy fix but that way you do not have to put in the old path line for each material that you load. You can create a directory even as DEFAULT for new and everytime you download a new maxwell material you can copy the textures to this default path and all you have to do in maya is load the material from the original location and it will look for the textures in the new location if you run the script.

Is that a bad idea.... or just a lazy one??


User avatar
By deadalvs
i know what You mean, but the path where the file is saved is just a string meaning a sequence of characters.

example: "ab34/khler/345glg.jpg"
if the drive is called: ab34/khler
how would maya know automatically/scripted that the file is called 345glg.jpg ? just not possible.

thus, the user recognizes the structure of the path, but there's nearly an infinite possibility how the prefix can look like. --> maya can not recognize the texture name out of the path (that «old path»)

You have to define it.

if the prefix were always 3 characters like T:/ or G:/, then, the script as Dr. Merman wrote it above would just delete the first three characters and then just add the new path.

but i wanted a script that lets define that exactly.

so: sorry...
Caustic render channels

Hello, Is it possible to have a pass with only th[…]

First Maxwell render for some time!

Hi, A just for fun project to model and render th[…]

Hi everyone, has anybody found a way to use and e[…]

Modeling from spline

Thanks - I came across the same thing myself recen[…]