Sunday, February 20, 2011

Select objects by material name

It's a MaxScript question posted in ScriptSpot, and here is the function I post to help:
-- function
fn findObjsByMtlName name = (
local theObjs = #()
theMtl = (for m in sceneMaterials where \ == name collect m)[1]
if theMtl != undefined do (
theObjs = for n in (refs.dependents theMtl) where \
superClassOf n == GeometryClass collect n

-- usage
select (findObjsByMtlName "Grass1")

Note that the function is case sensitive, ie "Grass1" is not equal to "grass1". I can modify it to become unsensitive using Max toLower() or toUpper() functions, but this way we risk to get more than one material and that is out of the goal.

No comments:

Post a Comment

Thanks for your comment