convert: undefined to type: String PROBLEM [SOLVED]

OldString = "Arch137" as string -- Change to suit
NewString = "AM137" as string -- Ditto
theMaps = getClassInstances BitmapTexture
for i in 1 to theMaps.count do (
	fileName = theMaps[i].filename
	if matchPattern fileName pattern:"AM*" ignoreCase:false == false then (
		newFilename = trimleft fileName OldString
		new2filename = NewString + newFilename
		theMaps[i].filename = new2Filename -- renames
	)
)

The above creates an error stated in the subject. I have tested this on 20+ scenes prior without any errors. I want to achieve is to replace 'string1' for 'string2' in the filename paths whilst not affecting the actual path.

As I've said it worked on 20 odd scenes prior.

Thanks for any help.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pixamoon's picture

`

oki,

Should be fixed now:

OldString = "Arch137"
NewString = "AM137"
theMaps = getClassInstances BitmapTexture
for o in theMaps where o.filename != undefined do (
    fileName = (filenamefrompath o.filename)
    --change file name only if match oldstring pattern  + "*"
    if fileName != undefined and matchPattern fileName pattern:(OldString+"*") ignoreCase:false then
        try(
            newFilename = trimleft fileName OldString
            o.filename = pathConfig.normalizePath ((getfilenamepath o.filename) + "\\" + NewString + newFilename)
        )catch()
)

there was one bitmap "Map #4413:Bitmap" without any filename in your scene. This will fix the problem:
 for o in theMaps where o.filename != undefined do (

This is if you want to make another rename script from scratch :)

If I understand you want to batch rename assets in multiple max files... Let me know if you want to try full version of Library Track/Relink? Its still not 100% finished but it does rename and repath job very easly...

Best,
Pixamoon

3dwannab's picture

THANKS VERY MUCH that has

THANKS VERY MUCH that has solved that undefined problem. I didn't notice that. Oh the shame! Thanks so much, I'm learning a lot. Only problem now is the trimleft function doesn't seem to be the right method to replace text strings. I really only used this to test but now I want to actually just replace x with y and so fourth. With trimleft it returns and results in:

trimleft "HDM_04_wordhere" "HDM_04"
"wordhere"

It takes out the _ before wordhere which is not what I was looking for.

I'm looking for a function to replace just what I type as opposed to affecting characters. I can't see one in the MS help, unless I'm blind! Any help here would get this finished I hope. I've done more tests with your the script and its much better than the built in asset tracker! I'd love to test it for you. I've noticed a bug in it. It doesn't update the assest tracker when you rename files etc. ATSOps.Refresh() should do the trick. Also when you open a new scene it doesn't update the list like asset tracker does. Apart from that, bravo!! :]

My new code looks like:

OldString = "HDM_04_10"
NewString = "HDM04_10_"
theMaps = getClassInstances BitmapTexture
for o in theMaps where o.filename != undefined do (
    fileName = (filenamefrompath o.filename)
    --change file name only if match oldstring pattern  + "*"
    if fileName != undefined and not matchPattern fileName pattern:(NewString) ignoreCase:false then
        try(
            newFilename = trimleft fileName OldString
            o.filename = pathConfig.normalizePath ((getfilenamepath o.filename) + "\\" + NewString + newFilename)
			ATSOps.Refresh() 
        )catch()
)

I've changed:

if fileName != undefined and matchPattern fileName pattern:(OldString)

to

 if fileName != undefined and not matchPattern fileName pattern:(NewString)

So that it only affects strings that DON'T have the Newstring in it. Seems to make sense to me anyway. :] And also added a refresh to the ATSOps But it's the trimleft problem which is helpfully the last of my issues. :) Thanks mate for your invaluable help so far!

pixamoon's picture

`

Good, so one problem away :)

and thanks for testing and suggestion... I'll add ATSOps.Refresh() to next version Thanks
and second - do u mean if you open new scene and Bitmap Tracking is still on it doesnt update.. thats true, I started as just resizing bitmaps script and it grows so much now... I'll add callback and if doesn't get slower. Actualy I think to remove hard Asset refresh on every open script, With big scenes it takes soem time to open it...

I send you also Library Track/Relink, let me know how it works...

and your code..
I used findSting instead of match pattern and then replace instead of trimleft or right
So then u can replace also in the middle of string

And u can keep not matchpattern to find it there is no new string but then use findstring ot matchpattern again to find out if there is old string. and than use replace... Hope this makes sense :)

Cheers,
Pixamoon

3dwannab's picture

HA! My turn to help you!

HA! My turn to help you! ;)

Thanks for the pointer. Here's my code snippet for that. With listener ouptut on last 3 lines.

fileName = "HDM04_09_testfilename"
OldString = "HDM"
NewString = replace fileName (findstring fileName OldString) OldString.count ""
"HDM04_09_testfilename"
"HDM"
"04_09_testfilename"

Different example code:

fileName = "HDM_04_09_testfilename"
OldString = "HDM"
NewString = "AM"
CombinedStrings = replace fileName (findstring fileName OldString) OldString.count ReplaceString
pixamoon's picture

`

yes, exactly, this is the way to do that

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.