Get texturemap name to output file

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 11 November 2013   #1
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: %,\nopa-texture-name: %,\n" 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?
 
Old 11 November 2013   #2
Thumbs down

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:\\test.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: % \n" 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 ",\nopa-texture-name: %\n" matopamap to:out_file 
					)
				)
			)
		)
	)
	close out_file
)
__________________
http://stigatle.no
 
Old 11 November 2013   #3
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.
 
Old 11 November 2013   #4
I had a similar question a while back,
we solved it in this thread:

http://forums.cgsociety.org/showthr...p?f=98&t=962272

Give that thread a read, and if you get stuck then just let us know here.
__________________
http://stigatle.no
 
Old 11 November 2013   #5
Thread automatically closed

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.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:13 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.