Home Technical Talk

maxscript to clear all texture references from a scene?

polycounter lvl 12
Offline / Send Message
gamedev polycounter lvl 12
Does this exist? Did a quick script spot search w/ no luck. I've got a bunch of textures being referenced in my scene, but none are visible in my mat editor. Short from eye dropper picking each object... i've got no way to clean em out!

Replies

  • Bryan Cavett
    Offline / Send Message
    Bryan Cavett polycounter lvl 19
    Try this out:
    Select your objects and run the script. It will condense the material editor for any unused materials and remove textures from any material in the scene. It doesn't work on every type of material but it should work on basic ones or even subobject ones. I haven't properly tested it but it should work ok. There's not a lot of error checking so if you run it on say a light it wont work so only select geometry. If I have time I might fix it but this should work as something quick for you.

    it should show up under "BCTools" in your hotkeys after you run the script once.


    EDIT:Just noticed that it will remove a map even if it has a submap. So say if you have a noise shader in the bump slot with texture maps it will just remove the noise map all together... not sure if thats what you need or if you are even using shaders like that. If you just using basic shaders with nothing being nested then it should be fine.
    macroscript removeTextureMaps category:"BCTools" toolTip:"removeTextureMaps"
    (
    	local getTextureSlots
    	with redraw off
    	(
    		editorOpen = 1
    		if MatEditor.isOpen() then editorOpen = 1 else editorOpen = 2
    		if editorOpen == 1 then MatEditor.Close()
    		macros.run "Medit Tools" "condense_medit_slots"
    		for i in 1 to selection.count do
    		(
    			getSubMats = getNumSubMtls selection[i].material
    			if getSubMats >  0 then
    			(
    				for p in 1 to getSubMats do
    				(
    					subMat = getSubMtl selection[i].material p
    					getTextureSlots = getNumSubTexmaps subMat
    					for k in 1 to getTextureSlots do
    					(
    						setSubTexmap subMat k undefined
    					)
    				)
    			)else
    			(
    				getTextureSlots = getNumSubTexmaps selection[i].material
    				for k in 1 to getTextureSlots do
    				(
    					setSubTexmap selection[i].material k undefined
    				)
    			)
    		)
    		if editorOpen == 1 then MatEditor.Open()
    	)
    )
    
  • cman2k
    Offline / Send Message
    cman2k polycounter lvl 17
    Thanks for that Bryan.

    Just a note to others:
    I have found many situations where max files have network references that are invalid. This could be because another artist referenced something on a network drive that I don't have mapped, for instance (think outsourcing, different networks, etc).

    If you are ever in a collaborative environment and find your autosaves taking 5-million years, it's probrably because you have a bad network reference, somewhere. And in situations like that something like this can save you a lot of time.

    This ones a keeper.
  • gamedev
    Offline / Send Message
    gamedev polycounter lvl 12
    Seems to work great for single objects, but errors out w/ multiple objects selected. Thanks for the script!
  • Bryan Cavett
    Offline / Send Message
    Bryan Cavett polycounter lvl 19
    hmm it shouldn't Does it error out or take a while? How many objects are you using it on? Ive only tested on max 2009

    edit:
    Here's a version with error checking to make sure you can only use it on the geometryClass
    macroscript removeTextureMaps category:"BCTools" toolTip:"removeTextureMaps"
    (
    	local getTextureSlots
    	with redraw off
    	(
    		editorOpen = 1
    		if MatEditor.isOpen() then editorOpen = 1 else editorOpen = 2
    		if editorOpen == 1 then MatEditor.Close()
    		macros.run "Medit Tools" "condense_medit_slots"
    		for i in 1 to selection.count do
    		(
    			if superclassof selection[i] == geometryClass then
    			(
    				getSubMats = getNumSubMtls selection[i].material
    				if getSubMats >  0 then
    				(
    					for p in 1 to getSubMats do
    					(
    						subMat = getSubMtl selection[i].material p
    						getTextureSlots = getNumSubTexmaps subMat
    						for k in 1 to getTextureSlots do
    						(
    							setSubTexmap subMat k undefined
    						)
    					)
    				)else
    				(
    					getTextureSlots = getNumSubTexmaps selection[i].material
    					for k in 1 to getTextureSlots do
    					(
    						setSubTexmap selection[i].material k undefined
    					)
    				)
    			)
    		)
    		if editorOpen == 1 then MatEditor.Open()
    	)
    )
    
Sign In or Register to comment.