PDA

View Full Version : Select Objects From Material


beuzel
04-27-2009, 02:13 PM
Hello

I am programming Python in Maya and I need to get the (part of the)mesh from a given material. Like the command "Select Objects from Material" in the hypershape window does. I want to know if a material uses a second uv-set. So if i would have the mesh i could do this?!


mc.select( clear=True )
shaders = mc.ls( type = 'shadingEngine' )
for shader in shaders:

#mesh = get the mesh here!

mc.select( mesh )
uvSets = mc.polyUVSet( query=True, allUVSets=True )
if len(uvSet) >= 1:
#has second uv set


Or does someone know how to access the relationship editor?
Has anybody a solution?

Greetings Chris

beuzel
05-14-2009, 08:43 AM
Hello,

My problem is still there.
I wrote the following code:

shaders = mc.ls( type = 'shadingEngine' )
for shader in shaders:
meshes = mc.listConnections( shader + ".memberWireframeColor", d=True, type='mesh')
for mesh in meshes:
mc.select( mesh, r=True )
uvSets = mc.polyUVSet( query=True, allUVSets=True )
len(uvSets) > 1:
mc.select( mesh, r=True )
uvSetName = mesh + ".uvSet[%d].uvSetName" % uvIndex
mc.uvLink( uvSet=uvSetName, texture=fileDG )

But i cannot rely on the memberWireframeColor connection. In some maya files the connection is not there but the material has a lightmap. I found a connection like mesh.instObjGroups[0] -> shadingNode.dagSetMembers[0] but they look slightly different in different files. Do you have a clue how to determine safety the mesh?

Thanks Chris

strarup
05-18-2009, 08:59 AM
Hi Chris,

eh... is it something like this?
get faces from object based on shader (http://forums.cgsociety.org/showthread.php?t=553699)...
eh... melbased not python... but might give some ideas... :)

not sure why you're using the memberWireframeColor thou...

you might maybe wanna have a look at the hyperShade command also...

kind regards

strarup

jaydru
05-18-2009, 10:04 AM
not sure if this is what your after

#with mat selected

import maya.cmds as mc

mc.hyperShade(objects="")

beuzel
05-19-2009, 08:32 AM
Thanks strarup and jaydru,
That was exactly what i needed!
Chris

CGTalk Moderation
05-19-2009, 08:32 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.