Material Replace

Anonymous

Material Replace

Anonymous
Not applicable

Hello! I'm a native C4D user trying to transition to Maya. In C4D, I can alt-drag a material on top of another to replace/overwrite that material everywhere in a scene. Is there an easy way to do this sort of thing in Maya? Maybe something to do with replacing node connections? No idea... Any help is greatly appreciated.

 

I need a quick method for this because my workflow often requires receiving sketchup models that have multiple shades of colors and I need a quick way of consolidating these... NEED to use maya for Unreal export capabilities.

0 Likes
Reply
Accepted solutions (1)
13,785 Views
13 Replies
Replies (13)

Anonymous
Not applicable

middle mouse button, drags nodes shaders and most things in maya, welcome to the maya super race. Oh and if you don't know anything about maya, its unstable as balls, save, save and save some more.

0 Likes

joostkonemann
Advocate
Advocate

You can do this in multiple ways (as most things in Maya), though one easy way is:

 

In the Hypershade, right-click and hold on a material and choose "Select Objects With Material". Right-click and hold on the material you want to assign and choose "Assign Material To Selection".

--
MacBook Pro 13,3 - 2.7GHz - 16GB - Radeon Pro 460 - macOS Catalina 10.15

Anonymous
Not applicable

thanks guys. i've heard of the 'select objects with material' 'assign material to selection' method before, but i need something with fewer clicks/movements. what do you mean by middle mouse click? which outputs do i connect?

 

also, back to the many material problem - are there any scripts that can overwrite multiple materials with one? or is there a way to select object assignments of multiple materials at once and reassign those to one material? again, i often get tons of grey colors from sketchup which should just be one grey. this would make it so much easier than having to recreate the materials in unreal when i export. thanks

0 Likes

Anonymous
Not applicable
Can you send me a small sample scene, I'll try script something for you but cant promise ill get it right. I'm not confident, this will be deep under the hood with tons of connections to be broken and made, why not just do it in C4D and then export your mesh obj/fbx to maya.
0 Likes

Anonymous
Not applicable
I suggest you move this to maya programming, you'll get better help there.
0 Likes

joostkonemann
Advocate
Advocate

The MEL script is quite easy (maybe it can be done in a more efficient way, but this works):

 

$target = `ls -sl -tl 1`;
select -tgl $target;
$selection = `ls -sl`;
for ($material in $selection) {
hyperShade -objects $material;
hyperShade -assign $target;
}

 

Select the materials you want to replace, select the target material last and run the script.

With the optimize scene command in the file menu you can afterwards remove all unused shading nodes.

--
MacBook Pro 13,3 - 2.7GHz - 16GB - Radeon Pro 460 - macOS Catalina 10.15

Anonymous
Not applicable

Awesome. I will try this after work (this is for a freelance project).

 

Also, I would do this in C4D, but the way C4D exports doesn't work correctly for UE4. I've narrowed it down to a material problem, as C4D saves FBX with its multiple material tags (a C4D specific thing), and UE4 overwrites them all with a single material. I've been working on a python script for it, but my programming skills are limited, so I've found it easier to learn Maya.

0 Likes

Anonymous
Not applicable
I was thinking that you go from C4D to maya via FBX. But if that script
works then it's all good. I'm also very new to scripting don't really know
python that well but I can get around.
0 Likes

Anonymous
Not applicable

Great script! Totally works. One thing. Is there a way to add an undo just in case I do something stupid? My monkey brain does funny things sometimes that I regret and undos really help to counteract it (if only they were included in real life as well). 

 

I've tried the C4D through maya thing before, but sometimes it imports a little weird, so I figure why not just learn Maya and join the masses who both worship and hate the all-powerful Autodesk?

0 Likes

joostkonemann
Advocate
Advocate
Accepted solution

With two extra lines the complete script can be undone in one go:

 

undoInfo -ock;

$target = `ls -selection -tail 1`;

select -tgl $target;

$selection = `ls -sl`;

for ($material in $selection) {

hyperShade -objects $material;

hyperShade -assign $target;

}

undoInfo -cck;

--
MacBook Pro 13,3 - 2.7GHz - 16GB - Radeon Pro 460 - macOS Catalina 10.15

Anonymous
Not applicable

You're awesome. Thanks

0 Likes

yanyangox3
Community Visitor
Community Visitor

wow!! 

0 Likes

stepienrafal
Observer
Observer

This is so perfect, it saved me hours of tedious clicking. Thank you!

0 Likes

Type a product name