Skip to content
On this page

Measuring Angle

In the following, we will introduce how to use mxcad plug-in to achieve the function of Angle measurement in CAD drawings. In this function, after the user chooses two unparallel lines, the Angle between the two lines will be marked according to the marked position set. The Angle measurement function can help users quickly grasp the Angle size between rectilinear line elements in the drawing, and facilitate the statistics of engineering quantities.

Function implementation

  1. Obtain the target line

We can through setting filter MxCADResbuf, Combining call MxCADUiPrEntity Select two unparallel target line objects to be measured in the drawing. During the selection process, in order for us to observe the selected line, We can call McDbLine.highlight() method to set the highlighted.

ts
// Set filter to filter out straight lines
const filter = new MxCADResbuf();
filter.AddMcDbEntityTypes('LINE')

// Select the first line
const getLine1 = new MxCADUiPrEntity();
getLine1.setMessage('Please select a straight line');
getLine1.setFilter(filter);
const entId1 = await getLine1.go();
if(!entId1) return;
const line1 = entId1.getMcDbEntity() as McDbLine;
// Set highlighting
line1.highlight(true);
// Select the second line
const getLine2 = new MxCADUiPrEntity();
getLine2.setMessage('Please select the second line');
getLine2.setFilter(filter);
const entId2 = await getLine2.go();
if(!entId2) return;
const line2 = entId2.getMcDbEntity() as McDbLine;
// Set highlighting
line2.highlight(true);
  1. Set the annotation position and draw the Angle annotation

According to the above steps, we have obtained two straight lines that need to be marked with angles. So we can call directly McDb2LineAngularDimension Set up the basic information of the angular dimension, call MxCADUiPrPoint take object setting the location of the label, And through the MxCADUiPrPoint.setUserDraw() Methods Dynamic Angle annotation was drawn. Among them, We can use McObject.addDimStyle() Method Set the basic style of the Angle annotation yourself.

ts
// Set the Angle annotation style
const dimStyleId = MxCpp.getCurrentMxCAD().addDimStyle("MyDimStyle2", "41,0.18,141,0.09,40,20", "77,1,271,3", "", "");
// Structural Angle labeling
const angleDim = new McDb2LineAngularDimension();
angleDim.xLine1Start = line1.startPoint;
angleDim.xLine1End= line1.endPoint;
angleDim.xLine2Start = line2.startPoint;
angleDim.xLine2End = line2.endPoint;
angleDim.dimensionStyle = dimStyleId;
// Turn off the highlight setting
line1.highlight(false);
line2.highlight(false);
// Set the Angle annotation position
const getPos = new MxCADUiPrPoint();
getPos.setMessage("Please set the location of the Angle annotation");
// Dynamic rendering
getPos.setUserDraw((pt, pw) => {
    angleDim.arcPoint  = pt;
    pw.drawMcDbEntity(angleDim)
});
const position = await getPos.go();
if(!position) return;
angleDim.arcPoint  = position;
MxCpp.getCurrentMxCAD().drawEntity(angleDim)

Functional practice

Practical effects are as follows:

  • Click the Measure Angle button to perform the measure Angle method
  • Select the target line object (click on two disjoint lines)
  • Set the point location
  • The contents of the measurement annotations were successfully drawn