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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Adding a layer to the mat color channel

    Scheduled Pinned Locked Moved PYTHON Development
    7 Posts 0 Posters 815 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 06/09/2013 at 04:33, xxxxxxxx wrote:

      Hi, I want to add a layer to the color channel and then insert in this layer multiple bitmaps / hdr's.
      The following script  code is not working

      The layer is created in the color channel, but the bitmap is not inserted?
      What am I doing wrong?

      import c4d
      from c4d import gui
        
      def main() :
          path = r"preset://prime.lib4d/Materials/HDRI/tex/HDR001.hdr"
          mat = doc.SearchMaterial("pim")
        
          shd = c4d.BaseList2D(c4d.Xbitmap)               #bitmap to be inserted under layer
          shd[c4d.BITMAPSHADER_FILENAME] = path
        
          layershd = c4d.BaseList2D(c4d.Xlayer)           #create layer for color channel
          mat[c4d.MATERIAL_COLOR_SHADER] = layershd 
          
          layershd.InsertShader(shd)      # insert bitmap under layer
          mat.InsertShader(layershd)       
          
          mat.Message(c4d.MSG_UPDATE)
          mat.Update(True, True)
          
          print "Done."  
        
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 06/09/2013 at 06:12, xxxxxxxx wrote:

        I have not really touched the layer shader yet, but I think we are not able to modify a layer shader 
        hierarchy programmatically (even in cpp). However a simple node structure (inserting just the bitmap 
        shader under the layer shader) won't work in any case, as such structure can neither provide the 
        blend mode nor the blend strength. Long story short - stick to the fusion shader.

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

          On 06/09/2013 at 06:38, xxxxxxxx wrote:

          You can only add shaders to the layer shader by inserting them under it. But you can not re-order them or change settings (blending mode, opacity, etc). This is a limitation of the Python API.

          -Niklas

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

            On 06/09/2013 at 08:44, xxxxxxxx wrote:

            ^Are you sure about that Nik?

            According to my notes. We cannot add things to the layer shader. Even with C++.
            But we can change their settings (change their colors, file paths, etc...).

            -ScottA

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

              On 06/09/2013 at 09:07, xxxxxxxx wrote:

              I think I have to agree with Scott.

              When I create a material with a layer with 2 images under it, I can read them and change them using GetNext, GetDown, etc.
              I can even add another image (bitmap) to the list, but the added image is not show.
              It is there, because the next time you read all the images, the added one is also displayed.

              Here the code.

              def main() :
                  mat1 = doc.SearchMaterial("MatPython")     #existing material with layer in color channel
                  shd = mat1[c4d.MATERIAL_COLOR_SHADER]      #layer has 2 images under it
                
                  lshd1 = shd.GetDown()
                  lshd2 = lshd1.GetNext()
                  print "lshd1 filenaam:", lshd1[c4d.BITMAPSHADER_FILENAME]
                  print "lshd2 filenaam:", lshd2[c4d.BITMAPSHADER_FILENAME]
                
                  #change the images
                  lshd2[c4d.BITMAPSHADER_FILENAME] = r"preset://prime.lib4d/Materials/HDRI/tex/HDR002.hdr"
                  lshd1[c4d.BITMAPSHADER_FILENAME] = r"preset://prime.lib4d/Materials/HDRI/tex/HDR010.hdr"
                
                  #add a new image
                  path10 = r"preset://prime.lib4d/Materials/HDRI/tex/HDR011.hdr"
                  shd10 = c4d.BaseList2D(c4d.Xbitmap)            
                  shd10[c4d.BITMAPSHADER_FILENAME] = path10
                  
                  shd10.InsertUnderLast(lshd2)       #insert the new image shader in the linked list
                      
                  lshd3 = lshd2.GetDown()        #check to see if insert was ok
                  print "lshd3 filenaam:", lshd3[c4d.BITMAPSHADER_FILENAME]
                
                  mat1[c4d.MATERIAL_COLOR_SHADER] = shd         #write it back to the material ???
                          
                  mat1.Message(c4d.MSG_UPDATE)
                  mat1.Update(True, True)
              
              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 06/09/2013 at 09:33, xxxxxxxx wrote:

                And how to change the layer image parameters.
                So, image on/off (the little eye icon), the mode (Normal, Multiply, Screen, etc.) and the slider on the right?

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

                  On 06/09/2013 at 09:54, xxxxxxxx wrote:

                  You are right Scott, I take back my previous statement :

                  Originally posted by xxxxxxxx

                  You can only add shaders to the layer shader by inserting them under it.

                  That you can not add new shaders or re-order them is also not possible with C++ (or at least not 
                  ovbious from the documentation). You can however read out the blend-mode and opacity and parameters
                  from C++ which is not possible from Python.

                  -Niklas

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