Notifications
Clear all

[Closed] request: Object-color to diffuse color-script

A have a number of scenes where a lot of objects have no material assigned but just an object color.
I have to find the object that have no material assigned, assign a seperate blinn material to each object en copy the object color to the diffuse color of the new material.

After a while this gets a bit tiring

I’m quite a max-script noob but is it possible to make a script for this and if so can someone point me in the right direction?

Thanks in advance.

5 Replies

Will this do the trick?

for i in selection do
(
	if i.material==undefined then
	(
		thecolor=i.wirecolor
		themat=standardMaterial()
		themat.name=i.name
		themat.diffuse=thecolor		
		i.material=themat
	)
)

Cheers!

If you’ve many objects… I would use this… the one above makes a new material for each object, this one makes a material only when needed and instances the material based on wirecolor via the name…


 for SelObj in Selection do
	(
	if ( hasproperty SelObj #material ) then
		if ( SelObj.material == undefined ) then
			(
		-- Creates name for material base on wirecolor
			local tnMatName = ("ColorMat-" + (SelObj.wireColor as string ))
		-- Makes an array of materials with same name, should only be one per scene
			local IsInScene = for chkMat in SceneMaterials where (chkMat.name == tnMatName) collect chkMat
		-- if array is empty make new material and assign, else apply material found in scene
			if ( IsInScene.count == 0 ) then 
				SelObj.material = StandardMaterial name:tnMatName Diffusecolor:SelObj.wireColor
			else
				SelObj.material = IsInScene[1]
			)
	)
 

Thanks guys! Kameleons script works for me, excellent timesaver.

Kramsurfer, somehow I couldn’t get your script to work but I’m probable doing something wrong. I saved the script as a .ms file, selected the objects without a material and executed the script by choosing Run maxscript ans selecting the .ms file.
If I’m doing something wrong please let me know. Thanks for your time!

Sorry, I wrote it without access to 3dsmax to test it…

The first if shouldv’e been IsProperty instead of hasProperty…


 for SelObj in Selection do
	(
	if ( isproperty SelObj #material ) then
		if ( SelObj.material == undefined ) then
			(
		-- Creates name for material base on wirecolor
			local tnMatName = ("ColorMat-" + (SelObj.wireColor as string ))
		-- Makes an array of materials with same name, should only be one per scene
			local IsInScene = for chkMat in SceneMaterials where (chkMat.name == tnMatName) collect chkMat
		-- if array is empty make new material and assign, else apply material found in scene
			if ( IsInScene.count == 0 ) then 
				SelObj.material = StandardMaterial name:tnMatName Diffusecolor:SelObj.wireColor
			else
				SelObj.material = IsInScene[1]
			)
	)

Thanks Keith. Don’t have access to max at the moment but I’ll try it first thing tomorrow!

Update: Tested the script and it workd like a charm now. Thanks!