Change or Convert Vertex Color of object (while keep the object as same type ex. Editable poly or Editable mesh)


#1

Hello, I am noob in 3dsMax Scripting.

I wrote a script to convert all vertex color to white. it works ok if I only select one object.
But If I select more than one object. It causes an Error. like this

Unknown property: “setVertColor” in undefined

here is the script.

Fn setAllVertexColor arrObj ColorSel:[1, 1, 1, 1] =
(
	for eachObj in arrObj do
	(
		print eachObj
		--print (classOf eachObj)
		if (classOf eachObj == Editable_mesh) or (classOf eachObj == Editable_Poly) do
		(
			local VertexCount = eachObj.verts.count
			--print VertexCount
			v = PaintLayerMod()
			addModifier eachObj v
			s = v.AcquirePaintState eachObj
			
			for ver in 1 to VertexCount do
			(
				s.setVertColor ver ColorSel
			)
			v.ApplyPaintState eachObj s
			collapseStack eachObj
		)
	)
)
x = selection as Array
setAllVertexColor x

Can any one help me identify where am I missing.


#2

add mapped before fn


#4

delete your first for while add mapped , this is just a better syntax
then for your problem , you use a method that must get reference notification from the interface of the PaintLayerMod modifier , you need select the object to achieve it
so ,select eachObj before you define s , and more important , set modifier panel on max modify mode first , without this , the interface won’t appear
if you need keep selection , then select x last


#5

Thanks

I simply solved the problem with this adding the

Select eachObj

in the code.

here is the working Script.

    Fn setAllVertexColor arrObj ColorSel:[1, 0, 0, 1] =
    (
    	for eachObj in arrObj do
    	(
    		print eachObj
    		--print (classOf eachObj)
    		if (classOf eachObj == Editable_mesh) or (classOf eachObj == Editable_Poly) do
    		(
    			local VertexCount = eachObj.verts.count
    			--print VertexCount
    			select eachObj
    			v = PaintLayerMod()
    			addModifier eachObj v
    			s = v.AcquirePaintState eachObj
    			
    			for ver in 1 to VertexCount do
    			(
    				s.setVertColor ver ColorSel
    			)
    			v.ApplyPaintState eachObj s
    			collapseStack eachObj
    		)
    	)
    )
    x = selection as Array
    setAllVertexColor x

#6

perhaps a simpler approach maybe…

fn reset_vcolor objset colour:(color 255 0 0) =
(
	for obj in objset do
	(
		if classof obj == Editable_mesh then 
		(
			meshop.setMapSupport obj 0 true;
			meshop.setVertColor obj 0 #all colour;	
		)	
		if classof obj == Editable_Poly then
		(
			polyop.setMapSupport obj 0 true;
			polyop.setVertColor obj 0 #all colour;
		)
		update obj;		
	)
)

reset_vcolor $objects colour:blue

#7

or …

mapped fn resetVertColor obj color =
(
	ops = case (classof obj) of
	(		
		editable_mesh: meshop
		editable_poly: polyop
	) 
	if ops != undefined do
	(
		ops.setMapSupport obj 0 true
		ops.setVertColor obj 0 #all color
		update obj	
	)
)

--resetVertColor objects blue

:wink:


#8

it did cross my mind that it could be done like that but I couldn’t be bothered to change it :smiley:


#9

“denisT” Thanks for the nice simple and effecient Script.

regards.

I am noob in Scripting. I had a question. Could you please tell me why in your script both the single object selection and the array of objects can work smoothly.
Is it because of the “mapped” in the begining of the ‘fn’ ?

In my script I had to use for loop to check all the object in an array of selected objects. and then run and execute the action.

thanks a bunch in advanced for your kind reply.


#10

Yes.

See the MaxScript Help: Mapped Functions