[Closed] Selecting objects by multimaterial properties
I have situation where I collect object with specified kind of materials parameters.
I could do it like: for n in objects where n.material==… do …
But when I work with thousands of objects it’s faster to do it other way around just
by searching in sceneMaterials and then go to object by materal dependency. This method work fine for materials however
it crash when there is multimaterial on scene.The core code look like this:
for o in objects do
(
for m in sceneMaterials do
(
selectmore( for n in (refs.dependents o) where superClassOf n == GeometryClass collect n)
)
)
can somebody help whit this one, I assume I have to loop by all multimaterials slots by how or maybe I`m wrong?
wrong. it’s always faster to go from object side if you do it right
now just simply explain what do you want to collect…
It’s hard to find a generic solution without a more detailed explanation of what you want to do.
Even so, it might also be not so simple to achieve.
For example, if you would like to select all nodes using a material with a specific diffuse color or map, what would happen if a material with a sub-material using that property is present?
At this point, any material that can host a sub-material would be a different challenge, considering the amount of renderers and materials out there.
There could also be more than one material with the same property as the one you want.
I don’t know is there is something like “get all materials with property ‘opacity’ and value 50.0”.
Perhaps something like the following script can work for you, but I find it a little cumbersome.
(
fn BuildScene =
(
--seed 1
resetMaxFile #noPrompt
m1 = standard diffuse:red
m2 = standard diffuse:green
m3 = standard diffuse:blue
m4 = multimaterial numsubs:3
m4[1] = standard diffuse:white
m4[2] = standard diffuse:[150,150,255]
m4[3] = standard diffuse:[150,255,150]
for x = 15 to 300 by 30 do
(
for y = 15 to 300 by 30 do
(
box pos:[x,y,0] wirecolor:[35,70,140] material:(#(m1,m2,m3,m4)[random 1 4])
)
)
)
fn SelectNodesByMaterialProperty prop val =
(
used = for m in scenematerials where isProperty m prop and getProperty m prop == val collect m
nodes = #()
for m in used do nodes += for j in refs.dependentNodes m collect j
max select none
select nodes
)
BuildScene()
SelectNodesByMaterialProperty "diffuse" (color 0 255 0)
)