Notifications
Clear all

[Closed] Filter String

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…

11 Replies

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);
 )
)

Thanks for that, that works perfectly! Cheers, although I used the replace string function rather than substring

NewTextureName = replace CurrentTextureName 1 3 “GEN_”

 lo1
if (substring oldTexName 1 3) == "_GE" do newTexName = replace oldTexName 1 3 "_GEN"
1 Reply
(@eddybrown)
Joined: 11 months ago

Posts: 0

Doh, I posted my edit before you posted this but that’s what I’ve done thanks!

 lo1

nice, I never realized you could use -1 in a substring to get the remainder.

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.

 lo1

this would not be correct, as it would turn “GE_ORANGE_1” into “GEN_ORANGEN_1”

1 Reply
(@noflame)
Joined: 11 months ago

Posts: 0

WOW! thanks to point out this.
I think i am just lucky that never get this situation before…

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.

2 Replies
 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

How does it cause a crash? It just returns an empty string, which would return false on the == “GE_” condition, as expected.

(@pjanssen)
Joined: 11 months ago

Posts: 0

Ah yes you’re absolutely right. So my previous comment can be ignored
I must have been confused with some other language there…