Multiline Text Example

This example demonstrates creating multiline text elements with layer-based colors. It shows how to define multiline text using an insertion point, string content (with newlines), height, and a bounding box width.

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

// Multiline text using layer color
var mtext = new MultilineText(
    insertionPoint: new Vector3(100, 220, 0),
    textString: "Multiline Text\nusing Layer Color\nspanning multiple lines.",
    height: 4f,
    rectWidth: 40f)
{
    Alignment = TextAlignment.TopCenter,
    LineSpacingFactor = 1.5f,
    LayerName = mtextLayer.Name
};
session.AddElement(mtext);

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

  • Multiline text elements are defined by an insertion point, text string (can contain \n for newlines), height, and a bounding box width (RectWidth).
  • The Alignment property controls the text block's alignment relative to its insertion point.
  • LineSpacingFactor adjusts the spacing between lines of text.
  • Each multiline text element is assigned to a specific layer for organization.
  • The multiline text's color is inherited from its assigned layer.