CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 02-22-2004, 09:04 AM   #1
pika
Frequenter
 
Join Date: Jan 2003
Posts: 108
Applying materials on object by corresponging names

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
 
Old 02-22-2004, 03:50 PM   #2
Asgaard
New Member
 
Join Date: Oct 2003
Posts: 17
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:

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

Code:
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
 
Old 01-17-2006, 01:00 PM   #3
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:53 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.