Adding a layer to the mat color channel

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.Update(True, True)
    print "Done."  
if __name__=='__main__':

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.

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.


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...).


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.Update(True, True)

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?

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.