PDA

View Full Version : Rename diffuse maps according to their bitmap name


SamSed
10-16-2009, 04: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!

bkravi
10-17-2009, 05:35 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.

SamSed
10-17-2009, 07:05 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
)

bkravi
10-17-2009, 08:29 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....

JHN
10-17-2009, 05:57 PM
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

denisT
10-17-2009, 06:50 PM
-- 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)
)

CGTalk Moderation
10-17-2009, 06:50 PM
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.