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.
By
Comments (15)
Comment policy
Regexpression example (Greaaaat success - Borat)
Strips filenames and paths only if missing from scene :) (much like relink bitmaps by colin senner)
FINISHED CODE (Case sensitive)
Code error in last code snippet NEW CODE HERE...
Listener output:
`
Hello again :) maybe something like this:
or just minimum addition to your code:
Hiiii, No...
First code you wrote still has that same error.
I've fixed the problem in my original code where it was replacing part of the filename with this particular scene by using 'fileName = (getfilenamefile theMaps[i].filename)' as opposed to 'fileName = theMaps[i].filename' but the error still crops up.
Full output from the listener using code:
Listener:
BTW do you know why the listener stops outputting when you run evaluate or eval selected line/code. Have to restart max to get it working.
I can send the test scene if you're willing to help. The way I want the format of the jpgs filenames is 'AM66_*.jpg' so the pattern would need to match 'AM' 'digits' 'underscore' 'anychar' 'ext'. Maybe I'm tired learning maxscript but I can't figure it out, plus the error which is more important.
Getting this to work would be a great timesaver. I tried looking for wxample codes also where say I want:
to allow different options that support wildcards. I know this is asking a lot. :)
MANY THANKS FOR HELPING SO FAR.
`
yes sure please send it.
But for renaming files or bitmap filenames in project you can use my Bitmap Tracking/Resizing... or cbuelter't Interactive Renamer
And yes, I know that "listener stops working" I had similar thing many times. What I found out only: it happens mostly if there is mistake in code and than it can't evaluate it or show error.
If I remember sometimes helps to delete what I changed last or try maybe to delete whole code, evaluate only with a = 1 and than undo detete ?? just an idea
also u have undefined error in other line:
new code:
or
:{([
Neither of those codes worked. I'm stumped. Sending scene and thanks for the trick. I tried evaluating a line of code I know was okay but I'll try your method next time. Don't mind the state of the scene I decimated the model.
Attachments
`
:( I don't have 2015 to test it
But looked in the the file with Library Track/Relink. And could see your assets list.
I test names in new scene with this new code:
Sorry I didn't noticed this before - you had:
It was trying to trim and rename all files other then "AM*"
I think it should look for oldString to machtpattern. Than will try to trim only files you want to rename...
Also for renaming you can use Bitmap Tracking Resizing or Library Track/Relink...
They have much more options to rename files in proj or on HDD etc.
Just a small screenshot how to replace in filename:
Thanks, the idea behind this .ms file is to run it with Batch it max over multiple directories and therefore saving tonnes of time in the long run :)
So far I've done a script to clean the assets how I like them found here: http://www.scriptspot.com/3ds-max/scripts/asset-cleaner minus the UI of course to work with BatchItMax and rename objects based on 'Filename + node type' and others like using relink bitmaps to find missing maps. and of course filter set to none and blur to 0.0. Things I find myself doing all the time on an individual basis.
Thanks for spotting the AM. I could replace that with:
to search that string anywhere in the string replacing any instances of it. I'd love if I could get regular expressions to work seeing as I know how to do that :) but maxscript is a different league but baby steps, baby steps. I've attached the scene in '14 format.
The new code is still throwing an error at:
Bangs head!!
Attachments
`
oki,
Should be fixed now:
there was one bitmap "Map #4413:Bitmap" without any filename in your scene. This will fix the problem:
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
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:
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:
I've changed:
to
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!
`
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
HA! My turn to help you! ;)
Thanks for the pointer. Here's my code snippet for that. With listener ouptut on last 3 lines.
Different example code:
`
yes, exactly, this is the way to do that
FOUND A SOLUTION TO THE LISTENER NOT WORKING
Place the cursor in the listener and hit escape a couple of times. :]