View Full Version : Script Select objects by UsedTexture bitmap

06 June 2011, 08:59 AM
Hi everyone.

I'm trying to find a way to Select objects by UsedTexture bitmap.
I explain, I have thousands of .3ds files that I need to import in 3DSMAX and apply a specific sub-material keeping the used textures.
The .3ds files are not always the same, some have only one diffuse texture used, some have 3 or 4.
The .3ds files are made in a way as every face (triangle) has his own single material and one object=2 faces. (Wall, roof)
So if only 2 texures are used, if my .3ds is made of 40 faces, I will have 40 materials sharing 2 diffuse textures.

I'm looking for a way to select objects by the used diffuse textures in order to apply a MaterialID to this selection and create a unique sub-material with the number of ID=number of textures used.
The part of the script to create the sub-material is already done, I only have to find the way to select objects by their diffuse map texture.

Can anyone help me please?

Many thanks.

Best regards.

06 June 2011, 07:43 PM
--loop through objects in the scene
for o = 1 to objects.count do
-- check to see if any objects have the same material as the first object in the array
if objects[o].material.diffusemap == objects[1].material.diffusemap then
--select the object with the same material as object 1
Select objects[o]
--make the objects material the same as the first object in the objects array
objects[o].material = objects[1].material

This might help you on to the right path. Its not exactly what you need but could be modified to be. I think I would actully have the loop store objects with matching maps in different arrays and then apply a material with that map to the array of objects.

06 June 2011, 04:48 PM
this returns an array of all objects using a specific bitmap. Currently it selects all objects. Just replace "your_texture_name.jpg" with your actual texture name.

theMap = "your_texture_name.jpg"
theObjs = #()
for i in (getclassinstances bitmaptexture) where (filenamefrompath i.filename) == theMap do (join theObjs (refs.dependentNodes i))
select theObjs

CGTalk Moderation
06 June 2011, 04:48 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.