copyToClipboard

Hi,
I’m new to GoJS. My useCase is to copy the nodes selected and paste them in the canvas.I know, it’s
the default behaviour of GoJs (ctrl+c & ctrl+v). But in my case, on copySelection, I want to access the data from GoJS clipboard, overwrite the nodes location to a specific location(let’s say ‘20 20’) and then copy updated nodes to clipboard again. So that, whenever ctrl+v clicks, nodes should be pasted on specific location(‘20 20’ in my case).
Right now, it’s pasting node right above it’s parent node
Here’s my code:

board.commandHandler.copySelection = function(){
board.selection.each(function(node){
node.data.loc = ‘20 20’
go.CommandHandler.prototype.copyToClipboard.call(board.commandHandler,node);
this._lastPasteOffset.set(this.pasteOffset);
})
}

I’m guessing that you have seen the implementation of the DrawCommandHandler extension, where there is this override of the standard “Paste” behavior (TypeScript):

  /**
   * Paste from the clipboard with an offset incremented on each paste, and reset when copied.
   * @return {Set.<Part>} a collection of newly pasted {@link Part}s
   */
  public pasteFromClipboard(): go.Set<go.Part> {
    const coll = super.pasteFromClipboard();
    this.diagram.moveParts(coll, this._lastPasteOffset, false);
    this._lastPasteOffset.add(this.pasteOffset);
    return coll;
  }

It keeps adding onto the _lastPasteOffset so that repeated pastes will keep moving the point where the newly copied parts are positioned.

But instead you could just call Diagram.moveParts with an offset that puts the copied parts where you want them to be. You can call Diagram.computePartsBounds to see where those newly copied parts currently are.

Thanks walter,
You gave me right direction. It worked.