ScriptSpot

Forum topic · General Scripting

undefined bitmap value for missing bitmap in scene

By David_Lee · 2013-05-25

Description

I'm working on a script that write a text file where collect all the bitmap path for each material in scene.
What I've done for now seems to works well, but only if all the maps are in some known folder.
If a material has a missing bitmapon it, it returns an error, due to a "undefined" value.

Here is my code.


txt = createfile "C:\bitmaplist.txt"		
MatID = 0
for mat in sceneMaterials do
(
	format "MATERIAL: = Mat-% = % = %\n" MatID mat.name (classof mat) to:txt
	for prop in (getPropNames mat) do
	(
		propVal = ((getProperty mat prop) as string)
		if (matchPattern propVal pattern:"*Bitmap") == true do
		(	
			bitmapPath = (getProperty mat prop).bitmap
			bitmapFileName = trimleft (bitmapPath as string) "BitMap:"
			scenePath =  substituteString (bitmapNewPath as string) "\\" "//"
			format "	Mat-% = % = Bitmap:%%\n" MatID (prop as string) scenePath bitmapFileName to:txt
		)
	)
	format "\n\n" to:txt
	MatID = MatID + 1
)

There are 5 days that I try to find a solution, without results.
Someone can help me, please?

Comments (8)

miauu · 2013-05-25

Max2013 + Vray. I created 2 teapots and added bmp1.bmp to the Bump slot of Teapot001 and bmp2,bmp to the Bump slot of Teapot002.
When I run you rscript everything is fine. I rename bmp2.bmp to bmp3.bmp, run the script and again everything is fine. The script prints old bitmap name. Strange.

Try this


bitmapPath = (getProperty mat prop).filename

instead of this:


bitmapPath = (getProperty mat prop).bitmap

It works for me and returns the file Path and file name of the bitmap in both cases.
Maybe I am doing something wrong.

barigazy · 2013-05-25

Maybe this can help somehow
Let say that we already collect all scene maps whitch contains some filename path in array named "scene_maps".
Then we can print anything in this case map name , property which include this path and file path

if scene_maps.count != 0 do
(
for m in scene_maps do
(
for p in (getPropNames m) where isKindOf (getProperty m p) String do
format "map: % ; property: % ; filename: %\n" m p (getProperty m p)
)
)

barigazy · 2013-05-26

I think that previous code supports any maps types (from differen render engines and plugins)

David_Lee · 2013-05-26

Yeah! With .filename the script works perfectly, thanks! :)

miauu · 2013-05-26

Glad to help. :)

miauu · 2013-05-25

I can't reproduce the error that you describes, but find which variable is undefined(when there is material with missing bitmaps) and on the next line of your script use

if myVAr !- undefined then
-- continue with the rest of the code
else
-- write to text file debug information or whatever you want.

Thanks miauuFor now i used

David_Lee · 2013-05-25

Thanks miauu

For now i used this solution to bypass the problem and continue to develop the rest of the script (writing path is only a little part of it).
But now I need absolutely to solve the problem... and I haven't found a solution yet.

To replicate the error, choose a scene that have a material with at least a bitmap.
Running the script, you get a txt file with the bitmap path wrote on it.

Here is what I see if the file is found:


MATERIAL: = Mat-1 = sofa_miro-12_53_03 = VRayMtl
	Mat-1 = texmap_diffuse = Bitmap:L:\3D Models\Sofas\leather.jpg
	Mat-1 = texmap_bump = Bitmap:L:\3D Models\Sofas\leather-bump.jpg

Now, look at the folder where the bitmap is and temporary rename it.
Open the max file again and run the script.

You'll probably get something like this:


MATERIAL: = Mat-1 = sofa_miro-12 = VRayMtl
	Mat-1 = texmap_diffuse = Bitmap:undefinedleather.jpg
-- Error occurred in Prop loop; filename: ; position: 1685; line: 56
--  Frame:
--   Prop: #texmap_bump
--   propVal: "Map #16:Bitmap"
--   bitmapFileName: undefined
--   bitmapNewPath: undefined
--   bitmapPath: undefined
--   called in mat loop; filename: ; position: 1913; line: 61
--  Frame:
--   mat: leather_glossy:VRayMtl
-- Runtime error: Error opening bitmap: leather-bump.jpg

Looking on the material, at the bump node I see the name of the bitmap file used.
But if i call via script the texmap_bump value, maxscript give me "undefined" instead of the file name.

David_Lee · 2013-05-25

What make me crazy is that in the error message max returns correctly the name of the bitmap i need!!
Reading the message, seems like he's trying to open the file...but I don't want to open it. I need only his name, nothing more!!