The easiest way to do this would be using Creator's batch run script tool (pro tool). The benefit of this tool is you can code your script to work on a single database, and the Batch Run Script tool will let you run that script on any number of files in batch. It has a UI to let you select folders of files or individual files to add to a list that will have one or more scripts applied to them.
Using this workflow makes the script trivial to write. Creator provides a nice to know function in the script editor to make things even more simple. To get started, simply use the insert code snippet command from the edit menu.
This menu provides access to common tasks in scripting like iterating database nodes, iterating palettes etc..
In this case if you select iterate texture palette, it will add the code to loop over all the textures in the palette for the current db and print out the name.
db = mgGetCurrentDb () print ('Texture Palette:') ret,index,name = mgGetFirstTexture (db) while (ret): print ('{0} : {1}'.format(index, name)) ret,index,name = mgGetNextTexture (db)
This code is very close to what you want. You just need to add the python function to convert a string to lower case, and the OpenFlight API function to replace a texture with another name.
Here is the same script from above with those two functions added and the un-needed print statements removed. (note that print statements slow down scripts dramatically, so they should only be used while debugging scripts or in key points that do not happen often)
db = mgGetCurrentDb () ret,index,name = mgGetFirstTexture (db) while (ret): lowername = name.lower() mgReplaceTexture(db, index, lowername) ret,index,name = mgGetNextTexture (db)
Ok, so now you should be able to rename all the rgbs in bridge, then run this script in Batch Run Script on all the files you want. I recommend using the backup files option in Batch Run Script just to make sure nothing gets broken.
nice! thank you....
would turning dashes to underscores throw a wrench into this?
Not at all. Just need to add the call to replace dashes with underscores.
something like:
lowername = lowername.replace('-', '_')
Added after line 4 above
heck yeah, this worked great....very much appreciated.
so what exactly is it doing? so the files wear already renamed in bridge...
so it gets the frist texture in the palette
then the lowername = name.lower() tells it to see that first texture as if it were all lowercase?
then the mgReplaceTexture replaces the texture naming to match the results from getting the lowername?
lowername = name.lower() creates a new string that is a copy of the name string but with all lower case characters
lowername = lowername.replace('-', '_') overwrites the lowername string with a new string that is a copy of it with all instances of - replaced with _
mgReplaceTexture tells creator to use the newly created string as the texture instead of the original without changing the index in the palette. (so no polygons need to change their index)
thank you. I do have a question about this. running this with the batch convert appears like it worked. i see a modified file call in the log.
opeing the model, nothing changed. if I run this script in the script editor, while the file is opened, it changes to relative like I want it to
db = mgGetCurrentDb ()
ret,index,name = mgGetFirstTexture (db)
while (ret):
mgTextureGetSavePathType(db)
mgTextureSetSavePathType(db,MSPT_Relative)
ret,index,
One important thing to know is that if a database is open inside of Creator, any scripts trying to open it will fail. Make sure it is not open while you are running the script. I don't think this is your issue, so I will take a look on my end to see if I can reproduce the issue.
gotcha..
i found this while digging in the forums
https://portal.presagis.com/support/discussions/topics/19000014067
there was a post from kentnichols that was pretty much what I was trying to do. I added
db = mgGetCurrentDb ()
mgTextureSetSavePathType(db,MSPT_Relative)
before his script, saved it and ran it on my files. appeared to work on all files i opend up so far.
I noticed it didnt get the textures that needed _ instead of -
from my last post, i had
lowername - lowername.replace('-', '_')
instead of
lowername = lowername.replace('-', '_')
i was needing to come back to this and ask about a texture with the same name but the file extension changed. need to swap .rgba textures with a .int
nameSwap = name.replace('.rgba' , '.int')
mgReplaceTexture (db, index, typeSwap)
this seems to be working
Yes that should do the trick.
John
I have a few hundred models that I need to rename the textures to be case sensitive. Can the whole process be done with the api? I was just going to batch rename all the rgbs in bridge, then the more tedious task of opening each model and selecting each texture and point to the new case sensitive texture.
I have not been able to keep up with learning the api/python since getting back into a few projects here. Very rusty, and wasnt that capable to begin with..