ScriptSpot

Forum topic · General Scripting

select object by diffuse map name

By jackieteh · 2017-10-11

Description

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 (3)

.

jahman · 2017-10-11

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 · 2017-10-12

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...

jahman · 2017-10-12

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