[Closed] Get texturemap name to output file
So im working on a script that scans all objects(geometry) in the scene, checks their materials and checks which materials uses a texturemap and that name should be exported in a .txt file list.
Here is what im using:
(
select geometry
tmesh = snapshotAsMesh selection[1]
out_name = ((maxfilepath)+ Getfilenamefile(maxFilename)+".txt")
out_file = createfile out_name
for o in geometry do
(
matdifmap = (o.material.diffuseMap.filename as string)
-- matopamap = (o.material.opacityMap.filename as string)
format "dif-texture-name: %,
opa-texture-name: %,
" matdifmap matopamap to:out_file
)
I want to have both the names of the diffuse and opacity map. However I get an error
filename is indefined (I assume this is because some objects dont have textures)
So when I add a try catch.
it exports to a .txt file but the filenames are written as undefined.
Where am I going wrong?
Hi, you need to add more checks before you try to read the data out.
Here’s how I would do it (many ways to solve it, this is just one way of doing it).
(
out_name = "c:\ est.txt"
out_file = createfile out_name
for o in geometry do
(
if (hasproperty o.material "diffuseMap")then
(
if (o.material.diffuseMap != undefined)then
(
if (hasProperty o.material.diffusemap "filename")then
(
matdifmap = o.material.diffuseMap.filename
if (matdifmap != undefined)then
(
format "dif-texture-name: %
" matdifmap to:out_file
)
)
)
)
if (hasproperty o.material "opacitymap")then
(
if (o.material.opacityMap != undefined)then
(
if (hasProperty o.material.opacityMap "filename")then
(
matopamap = o.material.opacityMap.filename
if (matopamap != undefined)then
(
format ",
opa-texture-name: %
" matopamap to:out_file
)
)
)
)
)
close out_file
)
Thanks stigatle, that script is working perfectly.
BTW There is no shorter way to grab both data at the same time? For example now its using same code for both the diffuse and opacity map. so if I want to browse through more slots (spec, gloss etc) the code will be very long. With similar pieces.
And last question, anyone know how to get the layername per object? i tried the layermanagergetlayer.name code but returns with an error.
I had a similar question a while back,
we solved it in this thread:
http://forums.cgsociety.org/showthread.php?f=98&t=962272
Give that thread a read, and if you get stuck then just let us know here.