How to Assign group id while pasting object inside group GoJS?

How to Assign group id while pasting object inside group GoJS?
We want copy multiple components and paste inside a group and auto assign group id when paste multiple Components inside a group.

The most common way to implement that would be to define a “ClipboardPasted” DiagramEvent listener, GoJS Events -- Northwoods Software

Alternatively you could override CommandHandler | GoJS API

How to get the group where selected components going to pasted?

That is a policy that you need to decide for your app. There are many reasonable choices.

Can you please give me an example?

Perhaps your policy would be to choose a selected Group. You would need to decide what to do if there are multiple Groups that are selected, if no Group is selected, or if the myDiagram.selection.first() is not a Group.

Or perhaps your app naturally has a Group that is the focus or is the main group, independent of selection. I have no idea of what your app looks like or how it behaves.

Or perhaps it should be the last created Group, assuming your app keeps track of that.

Or perhaps it should be some other way of deciding which Group to add to. I cannot decide this for you.

Our policy is Choose a group & paste Components.
When select multi group don’t want paste.

That sounds reasonable.
You will want to override CommandHandler | GoJS API as well as pasteFromClipboard.

I am using “ClipboardPasted” function. I want to know how to get group details where we are pasting components?

Look at the Diagram.selection.

I have use e.diagram.selection.toArray(), but it returns the pasted components. I can not find the function to found the group where paste is performed???

Ah, right – the “ClipboardPasted” DiagramEvent is too late to look at the selection before the paste. Look in the override of pasteFromClipboard