Applying materials on object by corresponging names

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  02 February 2004
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.

  02 February 2004

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 == 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 != 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...

  01 January 2006
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
Society of Digital Artists

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

All times are GMT. The time now is 08:33 AM.

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