Detecting duplicate nodes on an external drop

Continuing the discussion from Highlight links between nodes:

How are you deciding whether a node was a duplicate or not?

Maybe something like:

    "ExternalObjectsDropped": function(e) {
        e.subject.each(function(node) {
            if (e.diagram.nodes.any(function(n) { return n.category === node.category && !n.isSelected; })) {
                 ...
            }
          });
    }

Or substitute category with whatever criteria that you are using.

1 Like

Great. This worked. But the dropped item does not get deleted. Its stays hooked up to the mouse pointer.

Sounds like there was an error in your “ExternalObjectsDropped” event handler.

There isn’t any error in the event handler. Subsequent code executes fine. Would you suggest to check anything else ?

Are you using the debug version of the GoJS library?

Without the “ExternalObjectsDropped” DiagramEvent handler, does a drop work normally?

What is it that you are trying to do if you detect a duplicate? If you are modifying the dropped node(s), you should be able to modify them right then/there. If you want to cancel the whole drop, call e.diagram.currentTool.doCancel().

hi walter, I am using the release version. Drop works normally with “ExternalObjectsDropped” DiagramEvent handler.
After adding the recent line of code(doCancel()), I am able to find duplicate but not able to cancel the drop. The item still drops to the canvas.

e.subject.each(function(node) {
            if (e.diagram.nodes.any(function (n) {
                return n.category === node.category && (n.category === 'Start' || n.category === 'End') && !n.isSelected;
              
            })) {
               e.diagram.currentTool.doCancel();
                ShowPopupMessage("error", "Cannot drop duplicate block.");
            }
        });
1 Like

The problem is resolved now. I used below 2 lines to fix.

e.diagram.commandHandler.deleteSelection();
                e.diagram.currentTool.doCancel();

Thank you for all the assistance. :smile:

1 Like