Linear Dimension Example

This example demonstrates creating linear dimensions with layer-based colors. It shows how to define a linear dimension measuring the distance between two points.

using CadSDK;
using CadSDK.Elements;
using CadSDK.Enums;
using CadSDK.Geometry;
using System.Numerics;

// Create a drawing session
var session = new DrawingSession
{
    ExportFormat = ExportFormat.DWG,
    CadVersion = CadVersion.Cad2018
};

// Define layers
var dimLayer = new Layer { Name = "TestLayer_Dimensions", ColorARGB = AciColors.YellowGreen };
session.AddLayer(dimLayer);

// Linear dimension using layer color
var linearDim = new LinearDim(
    plane: Plane3D.WorldXY,
    extLine1: new Vector3(0, 250, 0),
    extLine2: new Vector3(100, 250, 0),
    dimLinePos: new Vector3(50, 260, 0),
    textHeight: 3f)
{
    LayerName = dimLayer.Name
};
session.AddElement(linearDim);

// Export the drawing
// You can signup and get your free API key
string apiKey = "your-api-key"; // Get your free API key from the dashboard
string outputPath = "drawing.dwg";
await session.ExportAndSaveAsync(apiKey, outputPath);
# Coming soon...

Key Points

  • Linear dimensions measure the distance between two points.
  • They are defined by two extension line origin points (ExtLine1, ExtLine2) and a point through which the dimension line passes (DimLinePos).
  • The TextHeight property controls the size of the dimension text.
  • The dimension's color is inherited from its assigned layer.
  • Plane3D.WorldXY is used to define the plane of the dimension.