Polyline Example

This example demonstrates creating polylines with layer-based colors. It shows how to define a polyline using a sequence of vertices.

using CadSDK;
using CadSDK.Elements;
using CadSDK.Enums;
using CadSDK.Geometry;
using System.Numerics;
using System.Collections.Generic; // Required for List<Vector3>;

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

// Define layers
var polylineLayer = new Layer { Name = "TestLayer_Polyline", ColorARGB = AciColors.Green };
session.AddLayer(polylineLayer);

// Polyline using layer color
var polyline = new Polyline(
    vertices: new List<Vector3>
    {
        new Vector3(0, 100, 0),
        new Vector3(50, 150, 0),
        new Vector3(100, 100, 0),
        new Vector3(150, 200, 0)
    })
{
    LayerName = polylineLayer.Name
};
session.AddElement(polyline);

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

  • Polylines are defined by a list of Vector3 vertices.
  • The Vertices property holds the sequence of points that form the polyline segments.
  • Each polyline is assigned to a specific layer for organization.
  • The polyline's color is inherited from its assigned layer.