Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Check in which channel a given shader is in

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 317 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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()
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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 loud 🙂

          thanks again

          1 Reply Last reply Reply Quote 0
          • First post
            Last post