Text Example

This example demonstrates creating single-line text elements with layer-based colors. It shows how to define text using an insertion point, string content, height, and alignment.

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 textLayer = new Layer { Name = "TestLayer_Text", ColorARGB = AciColors.Magenta };
session.AddLayer(textLayer);

// Text using layer color
var text = new Text(
    insertionPoint: new Vector3(0, 220, 0),
    textString: "Text using Layer Color",
    height: 5f)
{
    Alignment = TextAlignment.MiddleCenter,
    LayerName = textLayer.Name
};
session.AddElement(text);

// 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

  • Single-line text elements are defined by an insertion point, text string, and height.
  • The Alignment property controls the text's horizontal and vertical alignment relative to its insertion point.
  • Each text element is assigned to a specific layer for organization.
  • The text's color is inherited from its assigned layer.