PDA

View Full Version : Applying materials on object by corresponging names


pika
02-22-2004, 08:04 AM
Hello, I would like to do something like this using Maxscript.

If the name of material has "shpere_blue_mat"
then apply the material to all the objects that have
"shpere_blue" in the names.

I am new to this script and am wondering how I could start writing a script to accomplish this.

I may be able to start like this, but I am not sure how I can write a code that expresses "if part of material's name is equal to part of selected objects" part.

I am also thinking that I have to write a loop code that goes
through all the materials' names and objects name, then compare
each material name to each object's name.

Sorry about my vague question, but I appreciate any help that could get me somewhere.

Thanks

Asgaard
02-22-2004, 02:50 PM
Hi :)

Loop through all Materials, and loop again through all your Objects. The Compare the names and if they match, assign the Material.

A simple aproach would go like this:


for i = 1 to meditmaterials.count do
(

for obj in geometry do
(
if meditmaterials[i].name == obj.name then obj.material = meditMaterials[i]
)

)


It compares the full name of the Material and the Objects. So your Material and Objects need to share the same name.

Another Method is actually compare single parts of the string values.


for i = 1 to meditmaterials.count do
(

for obj in geometry do
(
if findstring meditmaterials[i].name obj.name != undefined then obj.material = meditMaterials[i]
)

)


This will search for the name of the Object in the given (given = i) Material name.
It works ok. But be carefull with numbers.
If you have names like "green" and "green2" it will not work properly, because the searchstring function will find both strings in the checked Material (for example "green2_mat" both "green" and "green2" will be detected)

so long...

-Asgaard

CGTalk Moderation
01-17-2006, 12:00 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.