[Closed] Get only ROOT materials of scene
Hi all
I have 2 materials and 2 objects in a scene
Material1 is standard material with blue color applied to a single object
Material2 is a multisub material with 6 submaterials named a,b,c,d,e,f applied to a single object
I want to get the root materials of the scene, so I expect to only get returned 2 materials, however I keep getting the subs in there also so its returning my expected 2 materials + the 6 subs
This is getting ALL scene materials:
for k in scenematerials do (print k)
I also tried this approach:
materials = for current in sceneMaterials where (superclassof current) == material collect current
but since they’re ALL materials, that also works on all 8 materials instead of the 2 I’m expecting
How can I modify that to get an expected result of only the 2 materials?
scene_mats = #()
for obj in objects where iskindof obj.mat Material do appendifunique scene_mats obj.mat
@Denis, have you ever written your own collectIfUnique() function? Would have thought it would have been right up your street for code line optimisation!
scene_mats = #()
for obj in objects where iskindof obj.mat Material do appendifunique scene_mats obj.mat
here is how it looks like in my code:
scene_mats = getmaterial objects exact:on unique:on
edited … there is another solution:
scene_mats = getAssignedMaterials()
the difference between first and second:
the first function can collect all sub-materials as an option and make pairs (Object, Materials) as a dictionary
both functions have an optional argument – class – where you can specify a searching material class
I was thinking as just a general array method not specifically for this use-case. I find myself often instanciating an array, and then using appendifunique, where collectifunique could cut a line out.
in this case i have a mxs class – valueset. It’s kind of dictionary. It’s collection and mappable (can iterate). it can be coerced as array
scene_mats = [b]valueset [/b](for obj in objects where iskindof obj.mat Material collect obj.mat)
One day, Denis will share his max goodie box and the world will rejoice.