How to add DimensioningLink to freehand drawn polygon

I am trying to add dimensions to the polygon which is drawn by the user. Can you help me in the code for polygon specifically?
PS: I have accessed the relevant links for the dimensions but was not able to get anything for freehand polygon drawing.

I don’t know what you mean. What do you want to show, and when?

This is for already defined nodes(Alpha,Gamma…)
I want this feature when i create a polygon drawing in the canvas.

Oh, do you mean while drawing the polygon? Like the WallBuildingTool and WallReshapingTool in the FloorPlanner sample? Floor Planner

Yes…
But these are predefined shapes like a wall is basically a line. Imagine I m creating a polygon in the canvas using PolygonDrawingTool. As soon as I finish drawing I want the dimensions to be displayed on the screen as in Wall in FloorPlanner.

Oh, so not while the FreehandDrawingTool is operating. I’m still unclear what you want to do. If you just want to show some information when that tool completes, you could override FreehandDrawingTool.doMouseUp to do that after calling the super method.

Or maybe you want to show that information about the (primary) selection, even if the user has not just drawn or is not drawing a polygon. That’s pretty commonplace, and there are many samples that demonstrate implementing a “ChangedSelection” DiagramEvent listener to look at the Diagram.selection and then update some HTML appropriately.

In very simple terms,

I want to merge these two features

There are many plausible ways of using PolygonDrawingTool and DimensioningLinks together.

You still haven’t clearly answered my question as to whether you want to show one or more DimensioningLinks during the operation of the PolygonDrawingTool, or after it finishes, or independent of it whenever the part holding the shape is selected, or some other circumstances.

After the PolygonDrawingTool has finished! Only Dimensions as shown for “Gamma” in the above link…

You can add some calls to Model.addLinkData in PolygonDrawingTool.finishShape:

PolygonDrawingTool.prototype.finishShape = function() {
  ...
  // create the node data for the model
  var d = diagram.model.copyNodeData(this.archetypePartData);
  // adding data to model creates the actual Part
  diagram.model.addNodeData(d);
  // add data for the dimensioning links
  var newkey = diagram.model.getKeyForNodeData(d);
  diagram.model.addLinkData({ from: newkey, to: newkey, category: "Dimensioning", fromSpot: "TopLeft", toSpot: "TopRight", direction: 0 });
  diagram.model.addLinkData({ from: newkey, to: newkey, category: "Dimensioning", fromSpot: "TopRight", toSpot: "BottomRight", direction: 90 });
  diagram.model.addLinkData({ from: newkey, to: newkey, category: "Dimensioning", fromSpot: "BottomRight", toSpot: "BottomLeft", direction: 180 });
  diagram.model.addLinkData({ from: newkey, to: newkey, category: "Dimensioning", fromSpot: "BottomLeft", toSpot: "TopLeft", direction: 270 });
  ...
};