Solved Remove object from layer

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.

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.

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

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.

@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. 🙂