Notifications
Clear all

[Closed] Collect and Move Maps to Folder

Two new scripts pretty basic. First one creates a .txt file of all the maps used in a scene. Second script copies all the maps from a list file to a designated folder.

(
 filesave = getsavefilename types:"TXT(*.txt)"
 filesave = (filesave+".txt")
 if filesave != undefined then
 (
  BT=getClassInstances BitmapTexture
  (
   dump = ""
   local mapfiles=#()
   fn addmap mapfile =
   (
 local mapfileN=mapfile as name
 local index=finditem mapfiles mapfileN
 if index == 0 do append mapfiles mapfileN
   )
   enumeratefiles addmap
   sort mapfiles
   for mapfile in mapfiles do 
   (
   append dump ((mapfile as string)+"
")
   )
   createfile filesave
   fstream = openfile filesave mode:"w"
   format "%" dump to:fstream
  )
 )
)

(
file = getopenfilename caption:"Open New-Line-Seperated Map List."
if file != undefined then 
(
 dest = getsavepath initialDir:("W:\\") caption:"Choose a Destination Folder."
)
if file != undefined and dest != undefined then
(
 open_file = openfile file mode:"r+"
 seek open_file 0 
 mapfiles = readDelimitedString open_file "~"
 mapfiles = filterstring mapfiles "
"
 for i = 1 to mapfiles.count do
 (
  newname = filenamefrompath mapfiles[i]
  newname = (dest+"\\"+newname)
  oldname = mapfiles[i]
  copyfile oldname newname
  )
)
)

38 Replies
2 Replies
(@davewortley)
Joined: 11 months ago

Posts: 0

Is there a way with this code to also list the Bitmap sizes at the same time? Would be very very useful to debug a massive scene we’re having problems with.

Also is there a way to get it to inspect in Xref Scene Entries?

(@zeboxx2)
Joined: 11 months ago

Posts: 0

The quoted code doesn’t appear to be valid; it collects the bitmapTextures into BT, but then BT is never used later?

Here’s one way, with additional checks:


 (
 	filesave = getsavefilename types:"TXT(*.txt)|*.txt"
 	if filesave != undefined then
 	(
 		deleteFile fileSave
 		fStream = createFile fileSave
 		for bmp in getClassInstances bitmapTexture do (
 			format "map: %
" bmp to:fStream
 			if (bmp.filename == "") then ( format "	-- no filename set
" to:fStream )
 			else (
 				format "	filename: %
" bmp.filename to:fStream
 				if (not (doesFileExist bmp.filename)) then ( format "		-- file does not exist
" to:fStream )
 				else (
 					bmpFile = openBitmap bmp.filename
 					if (bmpFile == undefined) then (
 						format "		-- file is not a valid bitmap file
" to:fStream
 					)
 					else (
 						format "		resolution: %x%
" bmpFile.width bmpFile.height to:fStream
 					)
 				)
 			)
 		)
 		close fStream
 	)
 	edit fileSave
 )
 

Sample output:


 map: Bitmaptexture:Bitmap
 	filename: c:	emp	est.bmp
 		resolution: 512x512
 map: Map #1:Bitmap
 	filename: c:	est.max
 		-- file is not a valid bitmap file
 map: Map #2:Bitmap
 	-- no filename set
 map: Map #3:Bitmap
 	filename: C:	est2.bmp
 		-- file does not exist
 

Thanks for sharing this.

Edit: I noticed a few debug lines still in and a typo. Let me correct those real quick… boy… for being inside of “code” tags… CGTalk sure is insistant on changing my paste.

I give up trying to get the formatting to ‘stick’. You get the idea. First script is based pretty heavily on one provided in the help documentation go ahead and check that one out it has some interesting peripheral information.

A shame “getClassInstances BitmapTexture” isn’t a surefire way to get all the bitmaps in a scene. For example, it won’t access the skylight map inside the brazil renderer. It also won’t get maps that exist inside a displace modifier.

  • Neil

I have had great success with it reporting bitmaps included in VRayDisplacement Modifier…not exactly sure what problems you’ve had soulburn. It works for me.

Yeah I actually only wrote the second script because I didn’t like how the “archive” option worked and I already had a TXT file with all the maps listed. But figured for ‘future generations’ that’s not really an efficient use of your time to archive/delete a bunch of maps just for a text file. Ideally you would just skip the file altogether and just export all the maps. But I was (and am short on time).

Does the file -> Archive list more thoroughly find all maps?

1 Reply
(@artofsoulburn)
Joined: 11 months ago

Posts: 0

Nope, it also, for example, misses any map in the render effects dialog.

  • Neil

enumerateFiles

should be the most effective use of collecting missing maps. Although I don’t like to use it mostly because it does things I don’t expect (like calling the <function> twice for each file)

Maybe someone could shed some light on why it does that?
Thanks!

1 Reply
(@artofsoulburn)
Joined: 11 months ago

Posts: 0

Personally, I’ve never been able to understand the code behind the materials system.

Objects seem far more well laid out, if you want a property, you do something like myobject.property, you want a property of a modifier, you say myobj.modifier.property.

To get things in materials requires using numsubs, subAnims and you have to manually traverse the trees. And it seems like there’s a lot of junk in there that isn’t really useful, and lots of duplicate information.

Anytime I have to write a map or material related script, a little part of me gets scared.

  • Neil

Maybe the references solution can be useful in this situation : http://www.sloft.net/2005/11/26/maxscript-references/

For some scripts I’ve written in the past I used getclassinstances and searched through some modifiers on a “special case” basis (like displace mod as Neil said, and Hair/Cloth mods also have map slots that aren’t retrieved through getclassinstances) to get the bitmaptextures. It definitely doesn’t make for clean code.

refs.dependents gives me a reference to the material editor when supplying a node with the displacement modifier on it, even if the map in the displacement modifier isn’t instanced to the medit material array. refs.dependson yields the transform controller and some derived object classes… in which case I’d have to loop through the derived objects and employ more case-specific code.

So I’m still not sure how to get the maps from the modifier without doing some intense case-specific property checking, which is what we all try to avoid. Anyone know of a sure-fire way to do this? Not even Resource Collector grabs these maps.

Ya, there really seems to be no surefire way to collect all the maps in a scene, so in the past I’ve had to write a lot of special case code. I tried getClassInstances BitmapTexture in max8, and here’s the results…

Background map – works
displace modifiers – works sometimes (that’s pretty agrivating, sometimes it works, sometimes it doesn’t it seems)
displace spacewarps – works
max projector lights – works
brazil 1 & 2 projection lights – doesn’t work
brazil skylight map – doesn’t work
fog – works
render effects blur filter – doesn’t work

Oh, to actually have one function that returns it all

  • Neil
Page 1 / 4