Clicking on button in palette to start drawing a new link

now i add a button on the link in the palette,what i want to do is when i click on this button it allows me to link 2 classes
i use this function to draw links:

function drawLink(e, button) {
      var node = button.part.adornedPart;
      var tool = e.diagram.toolManager.linkingTool;
      tool.startObject = node.port;
      e.diagram.currentTool = tool;

Yes, that is basically right. However, please realize that the value of e.diagram for an event on a GraphObject in a Palette will be that Palette, not the Diagram where you want the user to start drawing a new link. The same problem exists with the button.part.adornedPart.

So you need to make sure the starting Node is in the main diagram and not in the palette, and that you are using the ToolManager and setting the currentTool of the intended diagram and not if the palette.

The problem is that i want to select the link from the palette and then draw this link between 2 nodes !!

Well, either on selection or on clicking the link’s button you could modify the LinkingTool.archetypeLinkData to customize the newly drawn Link. LinkingTool | GoJS API