PDA

View Full Version : name extention replacer


thehive
06-05-2009, 10:41 PM
hey guy i know what needs to be done , jus not sure how to go about doin it


jus need to change ie "blah.jpeg" to "blah.rgb"


any help would be awesome thanks

thehive
06-06-2009, 01:16 AM
From what i can see i need to strip the this line down

setAttr -type "string" GG_1.fileTextureName "C:/Documents and Settings/thehive2020/Desktop/GG.jpeg";


im guessin i need to define the old name and then a temp name with no ext then a new name with the ext . I could be way off let me know if anything thanks ill keep at it

thanks

mlefevre
06-06-2009, 01:37 AM
Hi

Using match and substitute command...


string $pre_suffix = "C:/Documents and Settings/thehive2020/Desktop/GG.jpeg";
string $component = `match "\\..*" $pre_suffix`;
string $new_suffix = `substitute $component $pre_suffix ".rgb"`;

..courtesy of Bryan Ewert and Maya's command docs. :)

thehive
06-06-2009, 02:23 AM
oh dude thank you da man

thehive
06-06-2009, 02:03 PM
One quick question, is there a way to get the selection of the file names into an array
then attach them to the string pre_suffix -> match all -> then substitute all the extensions.

the prob is i cant seem to list all the names of the names of the files all i get is (file1 file2 etc) i need

file1.fileTextureName "C:/Documents and Settings/thehive2020/Desktop/GG.jpg";
file2.fileTextureName "C:/Documents and Settings/thehive2020/Desktop/GG.jpg";

then match like you said then substitute


basicly all im tryin to do is

1. select all the texture in the hypershade
2. just replace .jpg with .rgb

any thoughts

thehive
06-07-2009, 12:07 AM
this is what i got so far , but the match is causing an error not sure if its becasue of the array.




//list the directory of all the images
string $pre_suffix [] = ` file -q -l -loc -typ directory` ;
// Match suffix
string $component = `match "\\..*" $pre_suffix`;
//replace all textures with .RGB
string $new_suffix = `substitute $component $pre_suffix ".rgb"`;



// loop through an change extensions to desired file type

for($i=0; $i<size($new_suffix); $i++)
{


// i know is is not right but is what Im trying to accomplish
but with multiple files if that make sense

setAttr -type "string" file_350zrebuild_1.fileTextureName "C:/Documents and Settings/thehive2020/Desktop/work/350zrebuild.rgb";



}



any help would be most appreciated thanks

mlefevre
06-07-2009, 08:41 AM
Hey,

Try this.

global proc extRename(string $ext)
{
//list all 'file' nodes in scene
string $fileNodes[] = lsType("file");

//lsType returns the last array index as <done>. Remove it from array.
string $done = "<done>";
string $doneArray[];
$doneArray[0] = $done;
$fileNodes = stringArrayRemove($doneArray, $fileNodes);

string $component;
string $new_suffix;
string $path;
//loop through each element in the array using for-in loop
for ($eachFile in $fileNodes)
{
$path = `getAttr ($eachFile + ".fileTextureName")`;
$component = `match "\\..*" $path`;
$new_suffix = `substitute $component $path $ext`;
setAttr -type "string" ($eachFile + ".fileTextureName") $new_suffix;
}
}

//example

extRename(".rgb")

Hope that helps :)

-matt

thehive
06-07-2009, 03:34 PM
whoa this is freakin awesome jus what i was trying to jus didnt know how to split it up, i need to work at mel scripting more , I really apprecieat the help Matt thanks a mill.



Cheers

CGTalk Moderation
06-07-2009, 03:34 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.