select object by diffuse map name

I want to write a script that can select object by diffuse map name, below is my script, but it didn't work when evaluate all.

clearSelection() 
for obj in geometry do
( 
if obj.material != undefined then
(
if obj.material.texmap_diffuse != undefined then
(
if obj.material.texmap_diffuse == "vray Wood - Cherry" then selectMore obj
)
)
)

It give me an error in maxscript listener as below:

-- Error occurred in obj loop; filename: ; position: 134; line: 6
-- Frame:
-- obj: $Furniture
-- Unknown property: "texmap_diffuse" in RevitMaterialDefinition1615190_1615596:Autodesk_Generic

Hoping someone cloud help me to firgure it out, thank you.

I am 3ds max design 2014 + vray user.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

try this

mapname = "some_map_name"
nodes = #()
for mtl in scenematerials where isProperty mtl "texmap_diffuse" do
(
    if mtl.texmap_diffuse != undefined do
    (
        if mtl.texmap_diffuse.name == mapname do join nodes (refs.dependentNodes mtl)
 
    )
 
)
select nodes
jackieteh's picture

Hi jahman, thank you for your

Hi jahman, thank you for your help, i use your code, it didn't show any error in the maxscript listener, but it didn't select anything from the scene...

Regards,

Jackie Teh
website: http://www.sporadicstudio.com/

jahman's picture

..

Oh, sure. Previous version will not work if material is nested inside any other material. This should work:

mapname = "some_map_name"
nodes = #()
mtls = #()
 
for mtl in material.classes where mtl.Creatable do 
(
	if isProperty (createInstance mtl) "texmap_diffuse" do join mtls (getClassInstances mtl)
 
)
 
for mtl in mtls where mtl.texmap_diffuse != undefined do 
(
 
	if mtl.texmap_diffuse.name == mapname do join nodes (refs.dependentNodes mtl)
 
)
select nodes

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.