Rename diffuse maps according to their bitmap name


#1

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!


#2
 

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.


#3

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
  )

#4

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…


#5
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


#6

-- 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)
)


#7

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.