View Full Version : Filter String
eddybrown 01-12-2011, 09:48 AM Hi guys,
I'm trying to knock up a script to rename the beginning of a bitmap from GE_ to GEN_
At the moment I'm using the following script but I realise it will look for all occurances of GE_ so I might get unwanted results for instance if the texture had orange_ in the name it would be renamed.
oldname = filterString CurrentTextureName "GE_"
temp = oldname[1]
for i = 2 to oldname.count do
(
temp = temp + "GEN_" + oldname[i]
)
NewTextureName = temp
I've used this script for changing single characters but never larger strings, however it's not working as I'd expect.
For instance it will change 3_Door_FreezerVRayCompleteMap.tga to 3GEN_DoorGEN_FreezerVRayCompleteMap.tga
I wouldn't expect it to change at all...
|
|
Pjanssen
01-12-2011, 11:09 AM
filterString splits the provided string on each occurrence of each character in the token string.
How about something like this?
(
local newTextureName;
if (matchPattern textureName pattern:"GE_*" ignoreCase:false) do
(
newTextureName = "GEN_" + (substring textureName 4 -1);
)
)
eddybrown
01-12-2011, 11:20 AM
Thanks for that, that works perfectly! Cheers, although I used the replace string function rather than substring
NewTextureName = replace CurrentTextureName 1 3 "GEN_"
if (substring oldTexName 1 3) == "_GE" do newTexName = replace oldTexName 1 3 "_GEN"
eddybrown
01-12-2011, 11:25 AM
if (substring oldTexName 1 3) == "_GE" do newTexName = replace oldTexName 1 3 "_GEN"
Doh, I posted my edit before you posted this but that's what I've done thanks!
newTextureName = "GEN_" + (substring textureName 4 -1);
nice, I never realized you could use -1 in a substring to get the remainder.
NoFlame
01-12-2011, 01:21 PM
if you use 3ds Max 2008 and higher. there is another function you can use.
if matchpattern oldTextureName pattern:"GE_*" do
newTextureName = substituteString oldTextureName "GE_" "GEN_"
more clear than using number to replace string.
this would not be correct, as it would turn "GE_ORANGE_1" into "GEN_ORANGEN_1"
NoFlame
01-13-2011, 01:21 AM
this would not be correct, as it would turn "GE_ORANGE_1" into "GEN_ORANGEN_1"
WOW! thanks to point out this.
I think i am just lucky that never get this situation before...
Pjanssen
01-13-2011, 08:07 AM
Just an additional note: to be safe, you should actually check the length of the string before using the substring function. Theoretically, you could get an input with less than 4 characters, which will cause a crash.
Just an additional note: to be safe, you should actually check the length of the string before using the substring function. Theoretically, you could get an input with less than 4 characters, which will cause a crash.
How does it cause a crash? It just returns an empty string, which would return false on the == "GE_" condition, as expected.
Pjanssen
01-14-2011, 10:35 AM
How does it cause a crash? It just returns an empty string, which would return false on the == "GE_" condition, as expected.
Ah yes you're absolutely right. So my previous comment can be ignored ;)
I must have been confused with some other language there..
CGTalk Moderation
01-14-2011, 10:35 AM
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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.