Change Color Object....

I have a simple(?) question for your.

I have create a little script that allows to assign a standard material in an object:

---------------------------------------------------------------------------------------

mat_obj = StandardMaterial()-- create standard material

rollout testcolor "Test Color"
(
colorPicker col "Bmc" color:(color 81 81 81)--create color pick
button ins "Assign Color to selection" --create button

on col changed new_col do mat_obj.diffuse = new_col --create new diffuse color for the StandardMarterial

on ins pressed do
(
$.material = mat_obj --- assign the color to the object
)

)
createdialog testcolor

------------------------------------------------------------------------------------
Now, if I have one object in the scene no problem.
With two or more object (Sphere,Box ecc.), when I assign the color of the first object is updated continuously...To understand the problem better evaluate the script above with two object.

My question is this:
How do I assign different colors in the different selected object without updated the color assigned and without closed the script rollout?

The workflow must be:

Select Object
Assign color with color picker to the object
Select second object
Assign new color to the second object
ans so..

Any Help?
Thanks in advance Michele

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Arindam's picture

select objects by wirecolor

How can I select objects by wirecolor with MAX script

br0t's picture

There is already a

There is already a macroscript built in Max for this. Customize UI -> Quads/Tabs whatever -> Category: All Commands -> "Select by Color".

with maxscript it could work like this:

select (for o in objects where o.wirecolor == (color 255 255 255) collect o)

Never get low & slow & out of ideas

Anubis's picture

You assign material as

You assign material as instance, there's why the color changed

$.material = mat_obj -- instance material
$.material = copy mat_obj -- unique material

but Marco posted yet a good snippet, you can use it.

my recent MAXScripts RSS (archive here)

Michele71's picture

Anubis Thanks for you reply!.

Anubis Thanks for you reply!. The suggestion of Marco is the best solution for me. However your solution is very useful to understand!
Again Thanks Michele

Marco Brunetta's picture

The problem is the scope of

The problem is the scope of the variables, by defining mat_obj before the rollout you are giving it a higher scope (and probably even making it global if that's the whole script). However if I understand correctly you need to create a new material every time that you assign the color to the selected object. A simple solution could be:

(
	rollout testcolor "Test Color"
	(
		colorPicker col "Bmc" color:(color 81 81 81)--create color pick
		button ins "Assign Color to selection" --create button
 
		on ins pressed do
		(
			$.material = standardMaterial diffuse:col.color --- assign the color to the object
		)
	)
	createdialog testcolor
)

This way whenever you hit the button, the script creates a NEW material using the color currently in the colorPicker as diffuse color.

Michele71's picture

Yes Marco, You've hit the

Yes Marco, You've hit the target! :)
Honestly, I do not believe that the problem was the variable(mat_obj)! I never finish to learn new things...
So, if I understand correctly, this type of variable it is better to include in the execution strings?

So, Thanks 1000 Marco! :) :)

Budi G's picture

hi, Michele ... i try to help

hi, Michele ...

i try to help you a bit by example, seem like this :

---------------------------------------- my data
mycolor = #(red,green,blue) -- 3 colour as array
 
myobj = #()
myobj = for i = 1 to 3 collect ( sphere pos:[(i*40),0,0,] ) -- create 3 sphere as array
 
---------------------------------------- execute assign color to target 3 sphere
 
for o = 1 to myobj.count do
(
  myobj[o].wirecolor = mycolor[o].wirecolor
)

I think you must compare the count between object and color first, and the count must be identical...

hope that's helped

regards

budi

Michele71's picture

Thanks Budi, but your answer

Thanks Budi, but your answer does not solve the problem...

The problem is when I insert the new color (or even the same) in the object selected.
If I select a object and assign any color to it (with pickcolor button), then I select a second object and assign with pickcolor another color to it, is also updated the first color set (my example written above)!
However, your example, I was of help. I try it with another solution ;)

Many thanks Michele.

Budi G's picture

ops... sory :D ... ok no

ops... sory :D ... ok no problem ;)

I want to answer your question... but the anubis and marco have resolve your problem ... exactly they're right

regards

Michele71's picture

Budi no problem! You I've

Budi no problem! You I've been helpful anyway and I thank you again :) With your response I learned something I did not know so, Thanks!!! :) :) :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.