set / get reflectance layer options

On 27/02/2018 at 04:48, xxxxxxxx wrote:

I try to get and set some values of a reflectance layer.

import c4d
from c4d import gui
def main() :
    mat1 = doc.SearchMaterial("MatReflectance")
    print "nr of reflectance layers: ", mat1.GetReflectionLayerCount()
    refl_shd = mat1.GetAllReflectionShaders()
    for rs in refl_shd:
        print "bitmap:" ,rs[c4d.BITMAPSHADER_FILENAME]   
        print "refl strength: ", rs[c4d.REFLECTION_LAYER_MAIN_VALUE_REFLECTION]	#!not working
    #setting a bitmap is working!  
    rs[c4d.BITMAPSHADER_FILENAME] = "del.hdr"      
if __name__=='__main__':

I get an error when trying to get the layer reflection strength (REFLECTION_LAYER_MAIN_VALUE_REFLECTION).

It is also strange that I have to use BITMAPSHADER_FILENAME to get the bitmap file name and not REFLECTION_LAYER_COLOR_TEXTURE. This is the constant I get when I drag this field into the console.


On 28/02/2018 at 01:31, xxxxxxxx wrote:

Hi Pim,

GetAllReflectionShaders Actually retrieve all shaders inside all reflections layers.
That mean if you add a BitmapShader or a Filter or any other shader, it will return you the shader. Not  the Reflection Layer.

So here a code sample to iterate over all the Reflection Layer.
The main purpose it to get the c4d.ReflectionLayer object for each layer.
Then you can use GetDataID to retrieve the base ID of all parameters for this ReflectionLayer and simply add the parameter ID you want to this base ID.

import c4d
def main() :
    mat = doc.SearchMaterial("MatReflectance")
    cntLayer = mat.GetReflectionLayerCount()
    for i in xrange(0, cntLayer) :  
        layer = mat.GetReflectionLayerIndex(i)
        print "refl strength: ", mat[layer.GetDataID() + c4d.REFLECTION_LAYER_MAIN_VALUE_REFLECTION]  
if __name__=='__main__':

With that said I really encourage you to read the C++ Manual and give a look at this blog post.

Best, Maxime

On 01/03/2018 at 02:11, xxxxxxxx wrote:

Hi Maxime,

Yes, that works. Thanks a lot.