Notifications
Clear all

[Closed] getclassinstances selection

I’ve been using

mats = getclassinstances VRayMtl

to make changes to all Vray materials in a scene but now I need to just make changes for selected object materials

for example I wanted to make the diffuse colour of all materials white with no map so I used

	mats = getclassinstances VRayMtl

	for mat in mats  do
		try(mat.texmap_diffuse = undefined
			mat.Diffuse = color 255 255 255
		)catch()

but now I don’t want to do this to all materials just ones associated with the selected objects.Is there a way to get material class instances from a selection of objects or do I have to go about this in another manner.

Cheers Rob

2 Replies

If you want to collect the materials you could use

(
  local mats = for obj in selection collect obj.material
)

To filter the materials collected, you can add a “where” clause to the loop.

Alternatively, you could use that loop to apply the changes you want to make directly, without collecting the materials in an array first.

Or if you have many multimaterials in your scene and want to avoid looping through them to check their classes, just add a target to the getclassinstances function. something like this could work

material_collection = #()

for o in selection where o.material != undefined do
	join material_collection (getClassInstances VRayMtl target:o.material)

makeUniqueArray material_collection