Notifications
Clear all

[Closed] Script for copying materials

Search is timing out on me right now. If I’m in a situation where I have several pieces of geometry with various materials applied, and I want those exact same materials applied to a copy of my geometry with the same names, is there a script that can do this automatically?

For example, if I have Box_01 through Box_10, each with their own individual materials, if I have a copy of Box_01 through Box_10–with all geometry keeping the same name–is there an easy way to get the materials copied from one set of geometry to the un-materialed set of geometry, aside from assigning everything individually?

I am a novice when it comes to scripting. I do not expect anyone to write the script for me, but moreso give a point in the right direction to either finding one that is already available, or getting started in writing one that will work. I’ve been searching online for additional help, while waiting for replies.

This will hopefully serve as atemporary work-around to a bigger problem that stems from taking a model from max, exporting as .obj, bringing into maya for animation, then exporting back out as an .obj with point cache information, which lost the material information from the original max model.

Any help is definitely appreciated. Thanks.

4 Replies

Hi :o)

Try this:


 for i in geometry do
 (
 	if i.material != undefined then
 	(
 		for j in geometry do
 		(
 			if ((j.name == i.name) and (j.material == undefined)) then j.material = i.material
 		)
 		
 	)
 )
 
 
1 Reply
(@4_low)
Joined: 11 months ago

Posts: 0

Thanks for the suggestion.

I get the following error:

-- Syntax error: at ), expected <factor>
 --  In line:  )

Using a scene with two boxes with identical names, one box has a material applied and named, one box has no material. Running the script yields above error.

Oh, realy??
I test with Sphere and It’s Ok!!
The script work with only Spheres… haha :rolleyes:
I’m sorry, I’m kidding you.

I don’t know… Here it is all right.
Copy ALL code, maybe you not past one “)”

ok tried again and it works. Probably missed a ) like you said.

cool. This defintely helps… thanks