Adding and managing documents Layers

  • On 11/03/2013 at 07:36, xxxxxxxx wrote:

    Hi everyone !
    I did a little search here and on cgtalk but couldn't find anything about the subject, and the sdk is still cryptic for me sometimes.. 
    Is there a way to create/delete a layer, set its name, add objects to it and so on ?
    I thought I can solve with this:
    but evidently I didn't understood how it works. 
    Basically what I would like to do is a script that creates a new layer, sets its name to something, and add selected objects to it. I'm ok (i think) with adding objects to the layer, but i can't figure how to add the layer itself.
    Any advice, example or reference I can check would be great !


  • On 11/03/2013 at 08:06, xxxxxxxx wrote:

    Hi Massimiliano,

    Methods dealing with layers are exposed in several classes: LayerObject, BaseDocument and BaseList2D.
    Here's a commented code snippet showing how to deal with layers:

    import c4d
    def main() :
        # Create a new layer
        layer = c4d.documents.LayerObject()
        # Set layer name (Calls C4DAtom.SetName())
        layer.SetName("New Layer")
        # Assign the active object to the newly created layer
        # (Calls BaseList2D.SetLayerObject())
        if op is not None:
        # Get the invisible root layer
        layerRoot = doc.GetLayerObjectRoot()
        # Insert the layer under the root
    if __name__=='__main__':

  • On 11/03/2013 at 08:26, xxxxxxxx wrote:

    wow, that was fast :) Thanks a lot Yannick.
    I wrongly interpreted a layer as an object "attribute" instead of an object itself, it makes more sense now :)


  • On 11/03/2013 at 08:44, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    I wrongly interpreted a layer as an object "attribute" instead of an object itself, it makes more sense now :)

    Yes, a layer is an entity inside CINEMA, not just an attribute or parameter.
    LayerObject (representation of a layer) inherits BaseList2D: C4DAtom->GeListNode->BaseList2D->LayerObject.
    I'll improve layers documentation because this isn't obvious.

Log in to reply