Get all Material/texture nodes connected to certain Material or Texture

Get all Material/texture nodes connected to certain Material or Texture

denisVFX
Contributor Contributor
4,453 Views
6 Replies
Message 1 of 7

Get all Material/texture nodes connected to certain Material or Texture

denisVFX
Contributor
Contributor

I need a solution to get all material/texture nodes connected to the Output of certain Texture or Material.

Material class has methods getSubMtl and getSubTexmap which returns all materials and textured connected to material. But I wonder why it don't have a method for getting output connections. 

For example I have a Bitmaptexture which is connected to diffuse slot of material1 and diffuse slot of material2. How I can get this material objects?..

0 Likes
4,454 Views
6 Replies
Replies (6)
Message 2 of 7

Swordslayer
Advisor
Advisor

You can get dependents of the map, and filter them based on your criteria. For example, if map is the texture:

dependentMaterials = for r in refs.dependents map where isKindOf r Material and not isKindOf r TextureMap collect r
0 Likes
Message 3 of 7

denisVFX
Contributor
Contributor

Thank you for a quick reply.

It works but collets all the nodes which are higher in hierarchy. But I need only nodes which are connected to this texture (or material)

map = meditMaterials[1].map2.texmap_diffuse
dependentMaterials = for r in refs.dependents map where isKindOf r Material or isKindOf r TextureMap collect r
for i in dependentMaterials do 
(
	print i.name
)
kerosene_lamp_body_Diffuse_map:Bitmap
#(kerosene_lamp_body_metallic_mat:VRayMtl, kerosene_lamp_body_mat:Blend, kerosene_lamp_body_dielectric_mat:VRayMtl)

 

2 vraymaterials and 1 blend material are in dependentMaterials , but Diffuse bitmap texture isn't connected to blend material....

 

ref_dependencies.jpg

is there any way to filter refs.dependents result so it will return only nodes which has direct connection the node?...

 

0 Likes
Message 4 of 7

Swordslayer
Advisor
Advisor

Then you use getSubTexmap:

 

fn isSubTexmap m ref is:false = 
(
	for i = 1 to getNumSubTexmaps m where getSubTexmap m i == ref do is = true
	return is
)

dependentMaterials = for r in refs.dependents map where isKindOf r Material and isSubTexmap r map collect r
0 Likes
Message 5 of 7

denisVFX
Contributor
Contributor

Thank you! It works excellent!

But I if there any easy and elegant way to find to which texture slot output connection is connected? (is it diffuse map, or reflection, or maybe it's connected to mix texture map color 1... )

0 Likes
Message 6 of 7

Swordslayer
Advisor
Advisor

Since it's going through all the slots anyway, it's easy to save the slotname in the same pass...

 

fn isSubTexmap m ref &slotName is:false = 
(
	for i = 1 to getNumSubTexmaps m where getSubTexmap m i == ref do (slotName = getSubTexmapSlotName m i; is = true)
	return is
)

dependentMaterials = for r in refs.dependents map where isKindOf r Material and isSubTexmap r map &slotName collect dataPair val:r slot:slotName
0 Likes
Message 7 of 7

denisT.MaxDoctor
Advisor
Advisor

since this task does not require a real-time solution and is not particularly time-critical, I would go the other way:

 

fn getTextureMapDirectConnections map = 
(
	cls = classof map
	tvps = getclassinstances cls astrackviewpick:on
	cc = for tvp in tvps where tvp.anim == map collect tvp 
)	

tt = getTextureMapDirectConnections map
-- where tt is a list of trackviewpicks... see MXS help for details:

 

 

TrackViewPick : Value
Instances of the TrackViewPick class store the result of a selection from the Track View Pick dialog.

 

A TrackViewPick value has the following properties:

<trackViewPick>.name : string

The name of the picked item as shown in the Track View Pick dialog.
<trackViewPick>.anim : subAnim

The subAnim for the item the user picked.
<trackViewPick>.client : MAXWrapper

The owner of the subAnim for the item the user picked. If the owner is a subclass of MAXWrapper, the MAXWrapper value for the owner is returned, otherwise a value of undefined is returned.
<trackViewPick>.subNum : integer

The subAnim index for anim in client.

 

 

Of course, we can always filter the list by client class or subAmin name (property).

 

0 Likes