Give a material to clusters with same name?

Discussions regarding Materials, Material-Compounds or Shaders, etc.
Post Reply
Bullit
Moderator
Posts: 2621
Joined: 24 May 2012, 09:44

Give a material to clusters with same name?

Post by Bullit » 18 Aug 2013, 19:52

I have a bunch of objects that were imported and these all have clusters with same naming system. What is the easiest way to give a material to all this clusters in different objects?

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: Give a material to clusters with same name?

Post by Hirazi Blue » 18 Aug 2013, 22:08

It could well be, that I misunderstand the problem, but couldn't this be relatively easily done with some clever use of wildcards (such as "*") in the so-called "Object Selection and Sub-object Selection text boxes"? To find a more practical answer (it probably is scriptable as well) you might want to post a little more about the naming that's in place.
Stay safe, sane & healthy!

Bullit
Moderator
Posts: 2621
Joined: 24 May 2012, 09:44

Re: Give a material to clusters with same name?

Post by Bullit » 19 Aug 2013, 17:51

Thanks. I wan't able to get via Sub-object Selection text boxes, it just returns to the number of objects selected.
The naming is just Glass_2 these are a bunch of windows.

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Give a material to clusters with same name?

Post by myara » 22 Aug 2013, 07:07

The easiest way I could think of, without scripting, would be wildcards like Hirazi Blue said but in your Script Editor.

If I understood you, you want to asign a material "X" to all your objects clusters named "Glass_2"

You could use

Code: Select all

#Python
Application.SelectObj("*.*.polymsh.cls.Glass_2")
To select the all the polymeshes clusters called "Glass_2" in your scene, and then use Assign Material.

note: Using wildcards in SelectObj could be a little slow, but you can also use wildcards in your cluster name.

Or you could script something like this:

Code: Select all

#Python
# Name your cluster
sCluster = "Glass_2"
# Name your Material and Material Library
sMat = "Glass_Material"
sMatLib = "DefaultLib"
#--------------------------------

si = Application
oPolys = si.ActiveSceneRoot.FindChildren("","polymsh")
oMat = si.ActiveProject.ActiveScene.MaterialLibraries(sMatLib).items(sMat)

for oPoly in oPolys:
	cl = oPoly.activeprimitive.geometry.clusters(sCluster)
	if (cl): si.CopyPaste ( oMat, "", cl )
This will assign the material called "Glass_Material" from the Material Library called "DefaultLib" to all the Polygon Meshes Clusters called "Glass_2"
M.Yara
Character Modeler | Softimage Generalist (sort of)

Bullit
Moderator
Posts: 2621
Joined: 24 May 2012, 09:44

Re: Give a material to clusters with same name?

Post by Bullit » 22 Aug 2013, 21:16

Weird, i tried what Hirazi Blue and you said today and it worked, just selecting in the sub component. Don't know what mistake i have made the other day. Many thanks Myara.

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests