[Closed] Relinking Bitmap Textures Script
Friends and family,
I’m writing a script that automatically relinks bitmaps for missing textures right inside the materials instead of through the Max auto-paths dialog which when you have many network drives can get slow. The script is about done, now just the code to relink the textures exactly.
What I am having it do is search for the missing texture “Giraffe.jpg” and when it finds that texture in a directory automatically sets the obj.material.diffuseMap.filename = the path it found for a new “Giraffe.jpg” texture.
The problem is complex shader networks like missing bitmaps inside of falloff maps/noise maps etc. How can I account for all of the possibilities when trying to relink the bitmap?
If in the diffuse slot there is a falloff map, and in the color1 slot of the falloff map there is a missing bitmap texture etc.
Needless to say there is going to be alot of try/catching going on. Perhaps someone could shed some light on this for me? I’ll be making the script public once it’s done.
Many Thanks,
-Colin
You should scan the complete scene tree (or at least all scene materials’ trees) recursively for any objects that are either of bitmaptexture class or have a property called filename (the latter case would catch ANY objects with missing file name, not just bitmaptextures.
MAXScript provides a quick enumeration method to find all missing file names in the scene, but this does not give you any info WHERE they are missing. So once you collect all missing paths, you would have to scan the scene to find any occurences of these paths in any objects (remember, even lights can contain bitmaps in their projection slots, just like Displace and Volume Select modifiers can)
There are lots of examples of such scripts that scan recursively the scene tree using indexed access to sub-anims.
I am using EnumerateFiles to easily catch the missing files, and I have max about to even tell me what objects are missing bitmaps with a click.
Some things I don’t quite understand about enumeratefiles is it seems to be calling it multiple times for each missing file, which it shouldn’t do. Some explaination would be helpful since Maxscript Reference doesn’t help much.
I understand the process, just not how to scan for an instance of classOf BitmapTexture, however how can I scan the obj.material if I don’t know where to look?
As always, thanks for your expertise Bobo!
Colin
Hi,
Another way could be to use the getClassInstances fn
ie:
maps = getClassInstances bitmaptexture
for m in maps do
(
if not doesFileExist m.filename then
(
m.filename= ... --replace filename here
)
)
Excellent, thanks a ton for that snipped ZBuff, I wasn’t aware there was a getclassinstances! Thanks for pointing me in the correct direction.
And thanks to BoBo as well
-Colin