Transferring materials between otherwise identical meshes

The setup:
I have two Maya meshes, A and B
Everything about them is identical, except the assigned materials, and translation
A has 3 materials assigned to various UV shells / poly islands
B has a default lambert material across all its UV shells

how do I apply the materials from A to B, and have them go to the correct faces, via a script?

found it:

pm.mel.transferShadingSets(sampleSpace=1, searchMethod=0)

1 Like

Bonus round: what if I need to transfer only between selected poly islands?

With poly islands, do you mean one mesh where you can double click without selecting the full mesh, just parts of the mesh, i.e islands of polys that are not merged to the rest of the mesh?
I haven’t really done the select connected faces in python so I don’t know the command. Whetether it’s “polySelectConstraint -shell”, but I guess you could either select a face of each island, then getting the material from the first polygon, apply it to all connected faces of the second.
Or maybe rather on a per selection basis, then loop through each face,

A question that came up just now. If I assign a materal to the object itself, like dragging a material and dropping it onto an object n the viewport. Or selecting every poly of that object and assign the same material. Is there any difference in how that material is connected to the object. I’m thnking dragginga dn droppng actually adds it to the shading of each face. Just haven’t thought too much about it, then I had this course in OpenGL that was very eye-opening. What actually happens under the hood.

By I mean UV shells. Poly islands may be the wrong term.
I ended up creating a 2 step copy/paste material tool that does not use transferShadingSets

“copy” finds and stores the shadingEngine associated with the selected face(s)
“paste” uses pm.hypershade() with some flags I can’t recall right now to assign to the selection.

1 Like

Ok, I don’t quite follow. Are you selecting faces, but then calculate which polys goes to which UV shell and assign material from first polygon to the polygons in UV shell?

Here’s more details:

I have two nearly identical models A and B. B was modified by another tool, and as a result B only has the default lambert shader. I want to copy materials form A to B. Model A has several shaderGroups, each applied to different UV shells: one for the head, one for the torso, etc. So for example I want to copy the material form the UV shell of the head on A onto the UV shell for the head on B

Alt+F12 sets Maya’s viewport selection mode to UV shells, I select a set of faces on A in this mode. So only the faces of a single UV shell ( and a single shaderGroup) are in the selection.

the “Copy” button in the tool will search the connections of the first face in the selection list for the shaderGroup it uses, and store it.

The user then selects a new UV shell on mesh B, and the “paste” button will apply the stored shader to the selected face

It’s not very robust - no provision for multiple shaders assigned to a single selection, but it solves the problem at hand