Notifications
Clear all
[Closed] Rename diffuse maps according to their bitmap name
Oct 16, 2009 5:03 am
Anyone know a script that does this? or help me build this by adding the missing code:
SelMat = medit.GetCurMtl()
nSbMats = SelMat.numsubs
for j = 1 to nSbmats do
(bitmp = getFilenameFile SelMat[j].diffusemap.filename
SelMat[j].name = bitmp
SelMat.names[j] =bitmp
)
Thank you!
5 Replies
Oct 16, 2009 5:03 am
SelMat = multimaterial() -- create multi sub material
nSbMats = (SelMat.numsubs = 2) -- set no. of sub mat to 2
meditmaterials[1] = SelMat -- get the material in material editor
--- now you need to manuall assign some bitmap texture to the sub material of SelMat and the run the following code.
for j = 1 to nSbMats do -- go through all sub mats and only enter loop if the sub material has diffuse map as Bitmaptexture, do not enter if it has any procedural map.
if (selmat.material[j].diffusemap)!= undefined AND classof (selmat.material[j].diffusemap) == Bitmaptexture do
(
selmat.material[j].diffusemap.name = getFilenameFile selmat.material[j].diffusemap.filename -- assign the bitmap texture name to the diffuse map.
)
make sure you reopen you material editor if you don’t see the updated name of your map.
Oct 16, 2009 5:03 am
Thanks Bkravi.
Actually, while waiting for an answer. i figured out the missing piece (pretty simple).
SelMat = medit.GetCurMtl()
nSbMats = SelMat.numsubs
for j = 1 to nSbmats do
(
bitmp = getFilenameFile SelMat[j].diffusemap.filename
SelMat[j].name = bitmp
SelMat.names[j] =bitmp
SelMat.material[j].diffusemap.name=bitmp
)
Oct 16, 2009 5:03 am
your code will not work and will produce error if your material has no diffuse map applied… or if there is any procedural map inside.
you need to have condition to test against all possible errors…
Oct 16, 2009 5:03 am
for b in getClassInstances bitmaptex do try(b.name = getFilenameFile b.filename)catch()
This will rename all bitmap texture maps in the scene to the bitmap filename. Don’t know if it’s exactly what you need, but it works.
-Johan
Oct 16, 2009 5:03 am
-- recursively rename all material's valid diffuse texturemaps using filname
fn renameDiffuseMaps mat = if iskindof mat Material do
(
if isproperty mat #diffusemap and isproperty (b = mat.diffusemap) #filename and \
iskindof (f = b.filename) String do b.name = getfilenamefile f
for i=1 to (getNumSubMtls mat) do renameDiffuseMaps (getSubMtl mat i)
)