Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 13-01-2003, 03:26 AM   #1
dannyngan
Registered User
 
dannyngan's Avatar
 
Join Date: Dec 2002
Location: Seattle, WA
Posts: 1,154
Thanks: 0
Thanked 1 Time in 1 Post
Default find object's material via mel

Is there a way to determine an object's material via MEL? Even better, is there a way to find the material that is assigned to a specific face? I haven't been able to figure this one out.

Thanks.
__________________
Danny Ngan
Animator | Amaze Entertainment
my website | my blog | my job

Last edited by dannyngan : 13-01-2003 at 03:40 AM.
dannyngan is offline   Reply With Quote
Old 13-01-2003, 05:37 AM   #2
dannyngan
Registered User
 
dannyngan's Avatar
 
Join Date: Dec 2002
Location: Seattle, WA
Posts: 1,154
Thanks: 0
Thanked 1 Time in 1 Post
Default

Nevermind, I found it.
__________________
Danny Ngan
Animator | Amaze Entertainment
my website | my blog | my job
dannyngan is offline   Reply With Quote
Old 13-01-2003, 05:51 AM   #3
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well, it can get a little complicated. It's not that bad to find the shading group (or groups) to which an object or its components belong. For example, if you have an object called nurbsSphere1 with a shape node called nurbsSphereShape1, this will show you the connected shading groups:

listConnections -type shadingEngine nurbsSphereShape1

Once you have the shading group names, you can figure out from that what materials are assigned, by listing objects that are connected to the shading group's surfaceShader, displacementShader, and volumeShader attributes. Usually the surface shader is the one you're most concerned with, so let's just look at that:

For this code snippet, I'll assume that you've selected the object you're curious about AND that it only has one material assigned to the entire object:


proc string getSurfaceShader (string $objName) {

// This assumes you want ONLY the shape node at the selected level of the
// hierarchy, for the object whose transform name is passed in as the argument.

string $myShapeNode[] = `listRelatives -children -shapes $objName`;
string $mySGs[] = `listConnections -type shadingEngine $myShapeNode[0]`;
string $surfaceShader[] = `listConnections ($mySGs[0] + ".surfaceShader")`;
return $surfaceShader[0];
}


So, to see the surface shader on nurbsSphere1, type

getSurfaceShader("nurbsSphere1");

This isn't a general solution because different components of an object (such as individual polys in a mesh object) can have different shading groups assigned, and this would only give you the shader for the first one. Also, if for some reason you have multiple shapes under one transform (weird, but could happen) this will only give you one of their surface shaders.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
mark_wilkins is offline   Reply With Quote
Old 13-01-2003, 05:52 AM   #4
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

actually Danny is there a better way than what I just did? What did you find? I'm curious! :-)

(now that I think about it there's probably a command that's a shortcut for this but I'm not sure I know it off the top of my head...)

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
mark_wilkins is offline   Reply With Quote
Old 13-01-2003, 06:05 AM   #5
Darkware
Subscriber
 
Darkware's Avatar
 
Join Date: Oct 2002
Location: USA
Posts: 1,172
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I always open hypershade and right click a shader and choose "select objects with materials." If you just have a shader assigned to a specific face, it will only select the face. If you're trying to find the material assigned to a face, however, you can run into problems. If I have a cube with two shaders on it, when I right click and choose material attributes, I will only get one of them. Thus, I only know what one of the shaders is and I cannot modify it. Simply put, organization can really pay off in situations like this; especially if you're working with a particularlly large scene. Here's the secret - NAME YOUR SHADERS! Window>Rendering Editors>Hypershade. You see all the shaders you have in your scene. Every time you create one, come to hypershade, right-click it, and rename it. That way, when you're looking for a texture, you just have to recognize the name and double-click it to bring up the attributes window.
__________________
www.Darkware3D.com

Last edited by Darkware : 13-01-2003 at 06:13 AM.
Darkware is offline   Reply With Quote
Old 13-01-2003, 06:09 AM   #6
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sure... however I thought Danny was asking how to do it in a MEL script. :-)

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
mark_wilkins is offline   Reply With Quote
Old 13-01-2003, 06:10 AM   #7
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

BTW I wasn't able to figure out in a brief look how to find materials associated with specific faces in a MEL script, but I'll look again when I have a little time.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
mark_wilkins is offline   Reply With Quote
Old 13-01-2003, 06:57 AM   #8
dannyngan
Registered User
 
dannyngan's Avatar
 
Join Date: Dec 2002
Location: Seattle, WA
Posts: 1,154
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks, Darkware, but I'm looking for a way to do this in MEL. I'll explain below.

Mark, thanks for the suggestion. AFAIK, that's the one of the simplest ways to get the shader from an object. But, as you said, that's only for shapes with a single shader. I am looking for way to do this at the face level for shapes with multiple shaders applied.

This is what I've found so far:

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

Doesn't look too complex, just a bit convoluted. I'll dig into it some more tomorrow night when I have the brain power to do it.

For those of you who are curious (other than Mark ), I'm writing a series of scripts to help me with my UV mapping process. My method of UV unwrapping is very similar to Craig Daughtry's (see his VIP tutorial) and is actually something I was doing in 3ds max long before I moved over to Maya. What I do is create several shaders with random colors and then visually plan out my UV shells by applying different shaders to face selections. Once I have all my faces assigned with shaders, I'll go through and planar project best fit on each of the "patches".

Here's what my mesh looks like when I'm assigning materials:



At the moment, I have a script that will automatically apply the planar projections and layout the resulting shells, but that script depends on specific shader names (I have another script that generates a user-defined number of shaders that are named correctly). I'd like to make the script a little more flexible by not relying on specific shader names. Basically, I want to generate an array of all shaders that are applied to a particular shape and then use that list of shaders to run my script.

Another thing I'd like to do is create a HUD element that displays the shader of the currently selected face. This is mostly to help me in my shell planning phase. It starts getting a bit crazy when I have 50+ shaders applied to my model, and I have to change shader assignments to just one face.

Anyhow, this is the moderately long answer for why I started this thread. Any help you guys can offer would be greatly appreciated.
__________________
Danny Ngan
Animator | Amaze Entertainment
my website | my blog | my job
dannyngan is offline   Reply With Quote
Old 13-01-2003, 11:39 AM   #9
mumbojumbo_13
Subscriber
 
mumbojumbo_13's Avatar
 
Join Date: Oct 2002
Location: The Land Down Under
Posts: 1,047
Thanks: 0
Thanked 6 Times in 6 Posts
Default

go danny no one touchs this forum for ages and then DANNY and now we all flock to it nice to see it being used, now i learning mel yay
__________________
Thanks for wasting your time reading this line.
mumbojumbo_13 is offline   Reply With Quote
Old 14-01-2003, 12:11 AM   #10
dannyngan
Registered User
 
dannyngan's Avatar
 
Join Date: Dec 2002
Location: Seattle, WA
Posts: 1,154
Thanks: 0
Thanked 1 Time in 1 Post
Default



I think it's even better that Mark is on the forums now. He definitely knows a heck of a lot more about MEL than I do. I mean, he wrote a book on it!
__________________
Danny Ngan
Animator | Amaze Entertainment
my website | my blog | my job
dannyngan is offline   Reply With Quote
Old 14-01-2003, 03:22 AM   #11
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

The one doesn't necessarily follow from the other...

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
mark_wilkins is offline   Reply With Quote
Old 14-01-2003, 03:58 AM   #12
dannyngan
Registered User
 
dannyngan's Avatar
 
Join Date: Dec 2002
Location: Seattle, WA
Posts: 1,154
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hehe... Well, I still think you know more about MEL than I do. I've only been using it for 8 months now.

Anyhow, I did some more searching around the web and found this on Highend3D:

http://www.highend3d.com/maya/mel/?s...=rendering#948

The script seems to work fine as long as I strip out the section that tries to open a HyperShade window (line begins "if ($foundShaders)"). It's probably the way the author has the script written -- I get an error everytime the script hits that conditional statement. The main part of the script, however, returns the .outColor attribute name for any shader that is assigned to the selected faces (works for multiple faces and shaders). As it is right now, it'll work for what I need. I'll probably end up tweaking the script to do what I want. Ah, the joys of MEL...
__________________
Danny Ngan
Animator | Amaze Entertainment
my website | my blog | my job

Last edited by dannyngan : 14-01-2003 at 04:01 AM.
dannyngan is offline   Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem solving many dynamic objects in a pile? rohiniduggal Dynamics & Special Effects 3 14-01-2011 07:26 PM
MEL headache! happymat27 Members Lounge 5 05-12-2010 09:43 AM
Strange Problem - Unable to change attributes for multiple objects anthonysw3 Technical Issues 4 04-12-2010 11:56 PM
MEL headache!! happymat27 Mel Scripts & Programming 1 03-12-2010 04:41 PM

Thread Tools





A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.