[Closed] Diffuse material, inconsistent behavior?
Hi,
for the last couple of days I have been struggling with a very puzzling behavior of Maxscript.
My task is very simple: I have to detect the diffuse color of objects in a scene.
I’m using the command:
If $.material.diffuse == color a b c then … (with a,b,c being values between 0-255)
but it doesn’t seem to work reliably nor consistently.
Then to make it simple I did a bunch of tests with the listener by entering the manual command:
$.material.diffuse
and this is what I received:
undefined
(color 51 51 51)
Well, having only 1 object selected one would expect only one answer, either undefined or a color, but not both!
Then without changing the selection I entered again the same command:
$.material.diffuse
and this is what I received:
(color 51 51 51)
which is what I would expect.
Can somebody explain to me why it is not consistent in the replies? Am I doing something wrong or am I missing something?
A suggestion would be appreciated because I really got stuck
Thanks!!
Sorry my English is not the best, so I hope I understand you right. With “$” you only can manipulate one selected object. When you want to work with a bunch of objects you need to work with a loop. Something like:
for i = 1 to selection.count do (
if selection[i].material.diffuse == color abc do (
[...]
)
)
Don’t cry. It’s very easy to compare colors or any value by using simple string comparation method
fn isSameColor diffuse color =
(
if stricmp (diffuse as string) (color as string) == 0 then on else off
)
-- let say we have to check if some material diffuse color have value (color 250 220 100)
clr = (color 250 220 100)
-- now loop through all selected objects
-- check if material is assigned and have diffuse property
-- and if state is true collect objects
for o in selection where o.mat != undefined and isProperty o.mat #diffuse collect
(
if isSameColor o.mat.diffuse clr then o else dontcollect
)
Thank you for your replies: very appreciated !
I had to struggle on it for a while but at the end I understood what the problem really was.
I am working on imported models, and it just so happens that the importer is not doing a proper job in assigning the material properties. I found out that by just comparing the “diffuse” property MAXscript must be also comparing other properties which had wrong mismatching values.
I found a way around it by comparing the single color components (R/G/B).
But still it would help me to figure out the real cause if I was able to get a report of all the materials properties at once and compare.
I couldn’t find the proper way to do that, except accessing the properties one by one like diffuse, ambient, glossiness, etc.
Any input ?
Thanks again !