How can I prevent duplication when dragging a node from palette


I have tried to drag a same node from palette, and I have noticed that new node come to have a new key.
If I want to prevent from dragging a same node that already been attached to the diagram, how can I check it in mouseDrop event function.

You probably should not be depending on the value of the node data key to determine whether or not you have “duplicates”.

Would it be OK for your app to remove any just-dropped nodes that duplicate previously existing nodes? Say your node data has a property named “color”, and you wanted to make sure each node had a unique color. Then you could do something like:

      $(go.Diagram, "myDiagramDiv",
          allowDrop: true,
          "ExternalObjectsDropped": function(e) {
            e.subject.copy().each(function(n) {
              var matching = e.diagram.findNodesByExample({ color: });
              if (matching.count > 1) e.diagram.remove(n);
          . . .

Note how that for the “ExternalObjectsDropped” DiagramEvent, the DiagramEvent.subject is the Diagram.selection Set.