SOLVED Mograph Camera Shader from Python

I'm trying to write a script to add the mograph camera shader to the luminance channel of a material, and then set the Camera target. I can insert other shaders, but I cannot locate in the documentation the correct way to instantiate that shader, nor how to modify the property of a shader once added to the material.

hello ,

here's an example on how to create a camera shader and set the link of the camera.

Be aware you need to create the shader using it's ID so it could be changed in the future.

I've used a script from @m_adam as a base and just added the camera shader stuff. You can thanks him a lot ^^


import c4d
from c4d import gui

def main():
    # Gets the active object
    if op is None:
        raise ValueError("op is none, please select one object.")

    # Retrieves the BaseDraw of Render View
    bd = doc.GetRenderBaseDraw()
    if bd is None:
        raise ValueError("no BaseDraw found")

    # Retrieves the scene camera
    cam = bd.GetSceneCamera(doc)
    if cam is None:
        raise ValueError("there's no camera")

    # Creates a default Cinema 4D Material, the created material only exist in the memory
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    if mat is None:
        raise RuntimeError("Failed to creates a new BaseMaterial.")

    # Inserts the material in the active document

    # Creates the Camera Shader
    #be aware you have to use the ID here but it can changed in future release
    sha = c4d.BaseList2D(440000050)
    if sha is None:
        raise RuntimeError("Failed to creates a bitmap shader.")

    # Defines the camera link inside the shader
    sha[c4d.MGCAMERASHADER_LINK] = cam

    # Inserts the shader into the material
    mat[c4d.MATERIAL_COLOR_SHADER] = sha

    # Checks if there is already a texture tag on the active object, if not creates it
    textureTag = op.GetTag(c4d.Ttexture)
    if not textureTag:
        textureTag = op.MakeTag(c4d.Ttexture)

    # If the texture tag is not available at this point, something went wrong
    if textureTag is None:
        raise RuntimeError("Failed to retrieves the texture tag.")

    # Links the newly created material from the textureTag Material link parameter
    textureTag[c4d.TEXTURETAG_MATERIAL] = mat
    # Changes the texture tag projection to UVW

    # Informs Cinema 4D something changed in the scene

# Execute main()
if __name__=='__main__':

Thanks that worked perfectly. I thank you both!