PDA

View Full Version : Get material for one object and assign to another


AndersEgleus
12-18-2003, 04:22 PM
Sorry for the newbie q but I'm finding the manual a bit vague to say the least.

How can I check what material one object has assigned to it and then assign that same material to another object using Mel?

Marcel
12-19-2003, 08:01 PM
This sounded usefull, so I took some time writing a script that does what you ask. Now the choice is yours:

a. Try writing the script yourself, I can help you if you are stuck..
b. I can give you the script directly (which is less educational but with instant gratification :) )

If you decide to try it yourself, here are some good examples on how to get the material from an shape:

http://www.ewertb.com/maya/mel/mel_a43.html

Choose wisely :cool:

AndersEgleus
12-19-2003, 10:46 PM
Wow, what a great teacher! Not only did you take the time to help me, but you also want to make damn sure I learn my homework :applause:

Well, I'm about as wise in the ways of shading networks as I am with Mel scripting (i.e. not very :banghead: ), but I did do some serious searching today, and found, among other things, the page you've linked to, much thanks to the "Mel scripts" thread here.

So I read some, tried some, banged my head against the keyboard, and read some more, until I at least had something vaguely resembling what I wanted to do.


// requires a selection of 2 objects,
// with the object with the wanted material to be selected last.
$sel = `ls -sl`;
$obj1 = $sel[0];
$obj2 = $sel[1];
$obj1Sh = `listRelatives -fullPath -shapes $obj1`;
$obj2Sh = `listRelatives -fullPath -shapes $obj2`;
$obj2SGs = `listConnections -source false -destination true -type "shadingEngine" $obj2Sh`;
sets -e -forceElement $obj2SGs $obj1Sh;


I didn't want to publish it yet in case someone had a better idea.

So, my choice is a), then b) - it would be nice to see if there's a more efficient way to do it.

Marcel
12-20-2003, 11:07 AM
Wow, you did that very fast! And you script is much smaller than mine too :).

I've attached my version to the post, rename it to .mel and put it in your scripts directory. You can bind the commands 'mvCopyMat' and 'mvPasteMat' to a hotkey or a shelf button.
Being slightly lazy, I used the procedures from that webpage, and I also took a slightly different approach. I have two scripts (in one file), one for copying and one for pasting (pasting works on multiple objects).

I think I will extend it in the future so that I can copy and paste to faces also, not only whole objects. There also need to be added some checks I guess, so that I don't copy/paste on non-geometry objects.

This is actually a very usefull script...I wonder if it would be possible to put a list of all materials in some sort of dynamic marking menu, that would be even better....

AndersEgleus
12-20-2003, 10:43 PM
Cheers Marcel!

You script looks a lot more stable than mine, but I had a very specific use for it (had to make a script similar to "ConnectPolyShape" but a lot simpler and customized for my own low poly workflow). Mel is pretty cool, but it can be frustrating if you're coming from Maxscript, which IMO is a lot better documented.

Thanks for the help, and thanks, especially, for making me aware of the "hypershade -assign" command, that will make my life a lot easier in the future :)

gmask
12-20-2003, 10:57 PM
Here's another way to do it..



string $s[]=`ls -sl`;

string $shade[]=`listSets -t 1 -ets -o $s[0]`;

sets -e -forceElement $shade[0] $s[1] ;

AndersEgleus
12-21-2003, 01:43 AM
Lol! Even simpler! Cheers gmask!

CGTalk Moderation
01-17-2006, 12:00 AM
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.