ImageGear .NET v25.1 - Updated
Create a CADEntity in DWG, DXF Formats
User Guide > How to Work with... > CAD > How To ... > Create a CADEntity in DWG, DXF Formats

DWG/DXF formats are primarily used for viewing blueprints. It is also useful when adding notes on blueprints. This is where CADEntity comes into play. With CADEntity you can create and manipulate content within the DWG/DXF and save it.

While the current implementation of CADEntity works in Model-space, it is intended for "annotation" purposes in Paper-space or 2D layouts.

Current instances of CADEntity that can be created:

The following code example demonstrates how to create a new CADCircle.

C#
Copy Code
using System.IO;
using ImageGear.Formats;
using ImageGear.Formats.CAD;

public static void CreateAndAddCircle(string path)
{
    ImGearDWGPage page = null;
 
    // Load the file.
    using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
    {
       page = (ImGearDWGPage)ImGearFileFormats.LoadPage(fileStream);
    }
 
    // Create CADCircle.
    CADCircle entity = page.CreateCircle();
    entity.Center = new double[] { 0, 0, 0 };
    entity.Radius = 5;
    entity.Color = new byte[] { 0, 0, 255 };
 
    // Add CADCircle to DWG.
    // Important! You must call UpdateEntity(CADEntity) for changes to
    // apply to the CADEntity.
    page.UpdateEntity(entity);
 
    // Center/zoom so that it is easier to find the new CADEntity.
    page.Camera.ZoomExtents();
}
VB.NET
Copy Code
Imports System.IO
Imports ImageGear.Formats
Imports ImageGear.Formats.CAD

Public Sub CreateAndAddCircle(path As String)
    Dim page As ImGearDWGPage
 
    ' Load the file.
    Using fileStream As New FileStream(path, FileMode.Open, FileAccess.Read)
        page = ImGearFileFormats.LoadPage(fileStream)
    End Using
 
    ' Create CADCircle.
    Dim entity As CADCircle = page.CreateCircle()
    entity.Center = New Double() {0, 0, 0}
    entity.Radius = 5
    entity.Color = New Byte() {0, 0, 255}
 
    ' Add CADCircle to DWG.
    ' Important! You must call UpdateEntity(CADEntity) for changes to
    ' apply to the CADEntity.
    page.UpdateEntity(entity)
 
    ' Center/zoom so that it is easier to find the new CADEntity.
    page.Camera.ZoomExtents()
End Sub