Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Remove object from layer

    General Talk
    3
    4
    709
    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.
    • SwinnS
      Swinn
      last edited by

      I have searched through the documentation and cannot seem to find a way to use Python to remove and object from a layer.

      for item in spline_id:
              layer = doc.GetLayerObjectRoot().GetDown()
              if layer.GetName() == "nd":
                  print layer.GetName()
                  layer.SetLayerObject(None)
      

      This is the code I am using. I am trying to remove the object from the nd layer. Can you help? Thanks.

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hi,

        maybe I am overlooking something here, but your code does not make much sense to me. You are using BaseList2D.SetLayerObject on layer, which is a LayerObject. This technically works, since layers are derived from C4DAtom (i.e. are also a BaseList2D), but practically makes very little sense. If you want to remove a layer from a nested layer structure, you have to use the hierarchy methods of GeListNode. If you want to remove anything else in the scene graph from an layer, you have to overwrite the layer with BaseList2D.SetLayerObject on that object - in your case that object would be item, assuming item is some kind of BaseList2D.

        Cheers,
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • P
          PluginStudent
          last edited by PluginStudent

          Like zipit said, SetLayerObject() is from a shared base class but supposed to be used on with thingy (object, tag, material):

          op.SetLayerObject(None)
          c4d.EventAdd()
          

          actually it is also possible just to edit the "Layer" parameter:

          op[c4d.ID_LAYER_LINK] = None
          c4d.EventAdd()
          

          Compare Layer Manual.

          1 Reply Last reply Reply Quote 1
          • SwinnS
            Swinn
            last edited by Swinn

            @PluginStudent said in Remove object from layer:

            op[c4d.ID_LAYER_LINK] = None

            op[c4d.ID_LAYER_LINK] = None
            c4d.EventAdd()
            

            did it! Thanks!
            As you can tell from my previous code, I am hacking my way through Python. If you saw the rest of it, you would probably have to sit down and maybe drink a Gatorade. Or something stronger. 🙂

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