Problems copy and paste nodes between diagrams


I have 2 diagrams. The Diagram#1 is the default and Diagram#2 appears after that I save Diagram#1

In Diagram#1:

When I copy a node and I paste it here, the node has a key with another number (not a negative number like a new node)

In Diagram#2:

When I copy a node from Diagram#1 and I paste it here, the node has the same key from Diagram#1 and when I save the Diagram#2 the original node disappears from Diagram#1 like cut & paste not a copy paste

How can I solve this?


Sounds like you have some shared data structures that probably should not be shared, or other side-effects (in event handlers?) that you do not intend.

I’m not supposed to be helping you any more because your support contract has expired.

Hi, I’m currently the same problem. I’m using this function. When GoJS paste parts in the second diagram, the function excecute fine, but the target part has the same Id as the source part.

 newModel.makeUniqueLinkKeyFunction = newModel.makeUniqueKeyFunction = function () {
      return IdGenerator.generate(); 

I’m using LocalStorageCommandHandler.

I just tried this, and it had the expected behavior:

    var myCounter = 10;

    myDiagram.model = $(go.GraphLinksModel, {
          function() { myCounter += 2; return myCounter; },
      nodeDataArray: [
        { key: 1, text: "Alpha", color: "lightblue" },
        { key: 2, text: "Beta", color: "orange" },
        { key: 3, text: "Gamma", color: "lightgreen" },
        { key: 4, text: "Delta", color: "pink" }
      linkDataArray: [
        { from: 1, to: 2 },
        { from: 1, to: 3 },
        { from: 2, to: 2 },
        { from: 3, to: 4 },
        { from: 4, to: 1 }