Hi Martin! I think is what I understood You.
Below I give snipets from my render-toolkit code.
It only extracts because this toolkit complikated and renderman-aimed.
But I hope it will come across you on the right ideas.
So if we really want geting info from selected obj then:
1. Getting list shading engines:
def getsListShadingEngines(currentObj):
sgConections = mc.listConnections(currentObj,t="shadingEngine", d=1)
if sgConections != None:
##remove duplicates from list
inicSgConnections =[ u for u in sgConections if u not in locals()['_[1]'] ]
return inicSgConnections
2. Finding shaders connected to shading engine:
def rpExportMetaDataSG(currentObj, currentSG, time):
mayaShadersList = []
co_shader_strings = "" # Its may co-shader special variable, in your case its may be ane variable
shaderStringContent = "
if mc.connectionInfo( (currentSG+".surfaceShader"), isDestination=True) == 1:
mayaShadersList = mc.listConnections((currentSG+".surfaceShader"))
##!!!!!Check -If Not Connect
currentMayaShader = mayaShadersList[0]
shaderType = mc.nodeType(currentMayaShader)
#print currentMayaShader
# Ok Martin - we know maya shader BUT if this "layer shader" or other specific shaders like "useBackground"
if shaderType == "layeredShader":
layerShadersConnection = mc.listConnections(currentMayaShader,t="lambert")
layerShadersConnection += mc.listConnections(currentMayaShader,t="blinn")
.....................................
unicLayerShadersConnection = [ u for u in layerShadersConnection if u not in locals()['_[1]'] ]
countLayers = len(unicLayerShadersConnection)-1
while countLayers >=0:
co_shader_strings = #// MARTIN, NEXT YOUR CODE FOR working with unicLayerShadersConnection[countLayers]
.........
countLayers -= 1
elif shaderType == "useBackground":
shaderStringContent = # In this case Your procedure for getting connected slots in useBackgound shaders
##elif shaderType == ##"Other specific"###:
else:
shaderStringContent = ### Your procedure for finding connected slots in current shader
return shaderStringContent #My procedure return string - but your code can return list of texture(file) nodes and file places on storage.
3. Example for working with finded(in consruction above) surface shader
def mMainShaderAttrs(currentMayaShader,time):
surfaceColorContent = ''
if mc.connectionInfo((currentMayaShader+'.color'), isDestination=1):
listColorTextures = mc.listConnections(currentMayaShader+'.color')
if str(mc.nodeType(listColorTextures[0])) == 'file':
mayaColorTextureFile = mc.getAttr(listColorTextures[0]+'.fileTextureName', time=time)
.................................
PS. I use time attribute as I work with animated shader attributes. You can remove "time" - flag
Alex Mirgorodsky.
Shading TD/ Lighting TD