ScriptSpot

Forum topic · General Scripting

Material name select

By Mrjacks2o · 2011-02-17

Description

Hi How can i select all the objects in the scene by its material name?
lets say material name is "Grass1" i want to have a button you press it and it only finds material name called "grass1" thanks

Comments (2)

try this

Anubis · 2011-02-17

-- function
fn findObjsByMtlName name = (
	local theObjs = #()
	theMtl = (for m in sceneMaterials where \
		m.name == name collect m)[1]
	if theMtl != undefined do (
		theObjs = for n in (refs.dependents theMtl) where \
		superClassOf n == GeometryClass collect n
	)
	theObjs
)

-- usage
select (findObjsByMtlName "Grass1")

* note - this function is case sensitive, ie "Grass1" is not equal to "grass1"

Mrjacks2o · 2011-02-20

Thanks allot! Works perfectly...
like i said before the forum needs you :)