AddCopy to a specific layer

I am using document.AddCopy method for a drag&drop implentation. But how can I add the copied objects to a specific layer?

One way is to make sure the source object(s) are in the layer(s) that you want. If it is in a different document, just make sure the GoLayer.Identifier is the same as the Identifier of the destination document’s layer to which you want to add the copied object. This works because GoDocument.AddCopy calls CopyFromCollection, which tries to preserve layers when copying objects.
Or, just make a copy of the object by calling GoObject.Copy() and then call GoLayer.Add to the layer you want.

I tried that already. doesn’t work. I need to copy some nodes from a palette to my layer. I have your code in the method :
protected override IGoCollection DoExternalDrop(DragEventArgs evt)
and I get and exception saying that the object must belog to the view or it’s document. I can avoid the exception using the line
GoObject newobj = this.Document.AddCopy(n, docPnt);
but this is adding the object to the default layer.
It works if I remove the new object from document and add it again to my layer, but it doesn’t look ok to me, I might get into troubles considering the raised events.
Also I would like to know how to calculate the point where the nodes are dropped like in DoExternalDrop method

What layers do you have in your GoPalette.Document? Does each layer have the same Identifier as the corresponding layer in your main GoView.Document? Is each item in the right layer?
Actually, why are you overriding GoView.DoExternalDrop? The default behavior ought to be fine.
Or do you need to decide dynamically which layer to add dropped objects? You can just call aLayer.AddCollection(goView1.Selection, false), normally in a GoView.ExternalObjectsDropped event handler.

no, there is only one layer on the palette, and multiple layers on the document where I drop objects from palette.
I override GoView.DoExternalDrop because I want to check the objects to e dropped, and remove some of them from selection.

OK, so that should be fine. You can have the code to manipulate the GoView.Selection in either an override of DoExternalDrop after calling the base method, or in an implementation of the ExternalObjectsDropped event handler.
By the way, remember that you cannot Remove objects that are in the Selection while iterating over the Selection. It would be easiest to iterate over a copy of the collection:
foreach (GoObject obj in goView1.Selection.CopyArray()) { … }

this is exactly what i am doing right now. But now, after iterating over the selection , how do i make sure my objects from the selection are “landing” on the specific layer??? This is my real problem!!

Just call GoLayer.Add.
Or if they all can go to the same layer, call GoLayer.AddCollection.

I don’t think so.
This means that I will have the same object on two layers.
Once on DefaultLayer(added by the base method DoExternalDrop, think) and once on the particular layer I add objects from code!

so, any idea how to change the layer after calling base.DoExternalDrop ?

An object cannot be part of two layers at once.
Did you try calling GoLayer.Add on the objects in the GoView.Selection (or AddCollection on the whole GoView.Selection)?

Ok, I understand now. I thought an object can be part of two layers , that was my mistake. I’m using GoLayer.Add and I am testing right now, hope to find no other problems. Thank you.