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

    Adding and managing documents Layers

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 406 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 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: http://chicagoc4d.com/C4DPythonSDK/modules/c4d.documents/LayerObject/index.html#c4d.documents.LayerObject
      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 !

      Cheers
      Massimiliano

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

        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:
                op.SetLayerObject(layer)
            
            # Get the invisible root layer
            layerRoot = doc.GetLayerObjectRoot()
            
            # Insert the layer under the root
            layer.InsertUnder(layerRoot)
            
            c4d.EventAdd()
            
          
        if __name__=='__main__':
            main()
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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 🙂

          Cheers
          massimiliano

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

            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.

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