Check in which channel a given shader is in
-
On 02/11/2015 at 10:51, xxxxxxxx wrote:
Hi everyone, I've made a little script to "search" the name or type of a shader among all materials and so far is working, I get the number of occurrences and in which material they are. So far so good, BUT...what if I want to know also in which channel?
Here's the code:
import c4d, os from c4d import gui def shadertree(shader,parola,nome) : # Loop through the BaseList k = 0 while(shader) : if str.lower(parola) in str.lower(shader.GetName()) or parola in str.lower(shader.GetTypeName()) : k = k+1 # Check for child shaders & recurse if shader.GetDown() : shadertree(shader.GetDown(),parola,nome) # Get the Next Shader shader = shader.GetNext() return k def main() : parola = gui.InputDialog('Search') if not parola : return mat = doc.GetFirstMaterial() nome = mat.GetName() n = 0 while(mat) : shd = mat.GetFirstShader() if shadertree(shd,parola,nome) > 0: print "Found "+str(shadertree(shd,parola,nome)) + " occurrences of '"+parola+"' in material: "+str(mat.GetName()) n=n+1 # Get the Next material mat = mat.GetNext() if n == 0: print "Not Found" if __name__=='__main__': main()
-
On 03/11/2015 at 07:06, xxxxxxxx wrote:
Hi,
actually the channels of standard materials are a historically grown internal construct. You probably already noticed, that there's no equivalent for BaseChannel in the Python SDK.
Furthermore you have to be aware, that channels exist only for standard materials (type c4d.Mmaterial), there are lots of other materials, that don't have the concept of channels (like Sketch and Toon, Hair and all those special materials like Banzi, Cheen,...).For standard materials you can get the shader of each channel by accessing the material directly (mat[c4d.MATERIAL_COLOR_SHADER] for example). A list of these IDs can be found in the C++ docs or of course you can simply drag the texture parameter of each channel to the console.
And a last thought: There are also objects that make use of shaders (like for example the Displacement Deformer), so you may want to consider iterating these as well.
-
On 03/11/2015 at 09:54, xxxxxxxx wrote:
Thanks Andreas, that make sense I guess.
I'm trying to think to a workaround, maybe iterating through all attributes of a material, check if they are texture slots and something is loaded in? Just thinking out loudthanks again