[Closed] batch Bitmaptexture Generate empty jpg file
HI all
After run the script ,Generate empty jpg file.for example,I have a multimaterial , it Contain material[1]、material[2]、material[3]、material[4],material[1].name is water,material[2].name is wood,material[3].name is Material #30,material[3].name is Material #31,There is two files under c:,water.jpg and wood.jpg,But after run the script
Contain two empty jpg file, Material #30.jpg andMaterial #31.jpg.I can not find a solution
Hope helps, thanks!
code:
curSelection = ($Selection) as array
for o in curSelection do
(
if classof o.material == multimaterial do
(
for i = 1 to o.material.count do
(
TheMat = multimaterial()
o.material[i].diffusemap = bitmapTexture()
lh = o.material[i].name
o.material[i].diffuseMap = Bitmaptexture fileName:("C:\\" + lh + ".jpg")
)
)
)
-
You can remove the o.material[i].diffusemap = bitmapTexture() line as you do that again 2 lines down.
-
You need to use some sort of if, case, or other test expression to ensure that only the “Wood” and “Water” materials get the bitmaps. Your current code creates a diffusemap for every material where the bitmap filename is equal to the name of the material. Something like this:
curSelection = ($Selection) as array
for o in curSelection do
(
if classof o.material == multimaterial do
(
for i = 1 to o.material.count do
(
TheMat = multimaterial()
lh = o.material[i].name if (lh == "wood") or (lh == "water") do ( o.material[i].diffuseMap.filename = ("C:\\" + lh + ".jpg") ) ) )
)
-Eric
Hi,PiXeL_MoNKeY
This approach can solve the problem temporarily,But if c:\ have four hundred jpg files
I will write if (lh == “wood”),if (lh == “wood”),if (lh == ” “)…,Too much trouble,Do have a better solution ?
For support of an arbitrary number of files you may want to replace the name test with a doesFileExist test. Basically you check to see if the map exist, if true you continue on with your diffusemap assignment:
curSelection = ($Selection) as array
for o in curSelection do
(
if classof o.material == multimaterial do
(
for i = 1 to o.material.count do
(
TheMat = multimaterial()
lh = o.material[i].name
bMap = ("C:\\" + lh + ".jpg")
if (doesFileExist bMap == true) do
(
o.material[i].diffuseMap = Bitmaptexture fileName:bMap
)
)
)
)
-Eric
[left]Thanks [left]PiXeL_MoNKeY, You helped me a great.[/left][/left]
[left][left]
[/left][/left][left][/left]