Notifications
Clear all

[Closed] Mass Material Manipulation Tools?

(I posted this also in the main forum but it may be better here).

I have some specific material-related things that I need to do to multiple objects and I’m wondering if there are already tools that do this. Obviously Maxscript is the answer but I am (still) very ignorant of scripting and I need to get these things done.

Let’s say I have an object named ‘whatever’ with a material assigned called ‘material #101’ and it uses a diffuse texture map that is named ‘f6b28c9.tga’.

There are 2 parts to the desire.

  1. I will use existing tools to rename the object name from ‘whatever’ to ‘objectA’. I need a tool that will rename the material to be ‘objectA’. And I want the texture map on disk to be renamed from ‘f6b28c9.tga’ to be ‘objectA.tga’. Is there an existing tool that will do this?

  2. The material assigned to the object is a multi-sub material. But the multi-sub is not needed and only the material in the slot1 is required. If I set the ‘Set Number’ function in the material to 1, all is fine. Or if I could just assign the material in slot1 to the object so that it would no longer be a multi-sub, that would be fine too. Is there an existing tool that will do this?

I should note that I need to do this to multiple selected objects at once… not just a single object.

Thanks for any ideas.

16 Replies

What’s the logic in naming the object “whatever” to “objectA”? No logic? just rename it no mater if it’s a box, or whatever? Renaming the objects is easily done with the Tools-> Rename object, but instead of “objectA” you’ll get “object001” or something like that, do you need it to be from A to Z? if so you’re limited to just about the number of letters in the alphabet.

Long story short, it’s scriptable, what you’re asking.

for o in selection do (
o.material = copy o.material
o.material.name = o.name
diffusePath = o.material.diffusemap.bitmap.filename
newDiffusePath = ((getFilenamePath diffusePath)+(o.name)+(getFilenameType diffusePath))
renamefile diffusePath newDiffusePath
o.material.diffusemap.bitmap.filename = newDiffusePath
)

or

for o in selection do (
o.material = copy o.material[1]
o.material.name = o.name
diffusePath = o.material.diffusemap.bitmap.filename
newDiffusePath = ((getFilenamePath diffusePath)+(o.name)+(getFilenameType diffusePath))
renamefile diffusePath newDiffusePath
o.material.diffusemap.bitmap.filename = newDiffusePath
)

for Multi-Sub.

(COMPLETELY UNTESTED)

Thanks to all for the ideas.

Artur,
Sorry I wasn’t clear enough. I can easily rename the objects using a variety of renaming tools (particularly Neil’s Soulburn Scripts). It’s the other functionality I need… renaming the material name to match the object name, renaming the diffuse texture file on disk to match to object name, and changing the diffuse texture used to the newly renamed diffuse texture file.

Gavin,
Thanks for that code I will give it a try.

Thanks again.

Try this:

(
	for i in selection do
	(		
		-- First let's check if the material applied is a Multi/Sub Object
		if classof(i.material) == Multimaterial then
		(
			--Let's create a unique name to use with this object/material/filename
			uname = uniquename "object_"
			--Copy the material in the first slot and let's work on that. I use copy to avoid instances like Pixel Monkey has stated on CGTalk
			umat = copy i.material[1]
			uFlag=1
			--Check if it's a Standard Material or a A&D and take care of the diffuse map file
			case classof(umat) of
			(
				Standardmaterial:
					(
						bFile = umat.diffusemap.filename						
						bPath = getFilenamePath bFile
						bExt = getFilenameType bFile
						bNFile = bPath + uname + bExt
						renameFile bFile bNFile
						umat.diffusemap.filename=bNFile
					)
				Arch___Design__mi:
					(
						bFile = umat.diff_color_map.filename
						bPath = getFilenamePath bFile
						bExt = getFilenameType bFile
						bNFile = bPath + uname + bExt
						renameFile bFile bNFile
						umat.diff_color_map.filename = bNFile
					)
				default:
					(
						print "Unsupported material"
						-- This flag will prevent the script from continue if the material class is different from the above, if
						-- you want the script to run even if the file isn't rename, just set the flag to 1
						uFlag=0
					)
			)
			
			if uFlag != 0 then
			(
				--Let's apply the material with the brand new diffuse filename to the object and rename the material
				i.material = umat
				i.material.name = uname
				
				--And finally let's change the name of the object and whe're done!
				i.name = uname
			)
		)
	)
)

Works with Standard and A&D Materials. Please run this at your risk, you should first do a folder with the scene and textures just to test this out or else you can loose your original textures as they are renamed.

Gavin,

Thanks for the code. Your multi-sub code works great! With one exception. The last line that attempts to set the diffuse texture to be the newly renamed bitmap file on disk is not successful in setting it to the renamed file for some reason.

I am actually using a .DDS filetype (not a TGA)… could that be the reason it’s not setting the diffusemap?

Thanks again.

Artur,
Thanks very much! That code works great. I will examine more closely your script… thanks for the comments as they really help to understand the logic. But I would probably like to rename the objects outside of the script so I will have to tweak it for that.

Gavin,
I was able to fix the last line of code and it works great now as well.

Thanks again!

No problem, glad to help if you want to rename the objects first with anoter tool you just have to change two lines in my script

(uname = uniquename “object_”) to (uname = i.name)

and
comment the last line:
(i.name = uname) to (–i.name = uname)

About Gavin’s code, there’s actually a pretty weird bug in o.material.diffusemap.bitmap.filename but if you change all that instances to o.material.diffusemap.filename it should replace the new string in the filename correctly.

Cheers!

Mike, Artur, and Gavin,

don’t rename texture files. create a copy with a new name. at least you will get a chance to revert everything back.

Hey Denis, I thought of that also, but since he was asking for a rename… he got what he asked for

But Mike if you want to copy the files instead of renaming, error-avoiding wise, just say so.

Page 1 / 2