Free .NET Library for AutoCAD DXF & DWG Reading & Writing
Open Source .NET CAD Library That Enables Programmers to Open, Read, Edit, Write and Convert AutoCAD DXF & DWG Drawings with ease.
What is ACadSharp?
ACadSharp is an incredible Open Source C# .NET Library. It offers software developers the ability to work with AutoCAD DXF & DWG drawings in their C# applications. This library comes packed with key features like adding new elements to CAD drawings, deleting unwanted elements, accessing all entities in the model, creating duplicates of specific elements, generating arcs from bulges, refining MText, and crafting various entities. With ACadSharp, you have the tools to enhance your C# applications with AutoCAD file management capabilities.
DXF and DWG files are widely used in the CAD industry as they show vector images. They both offer similar high quality and are commonly used to share data between various CAD and drawing programs. DXF is a standard supported by Autodesk, Inc., while DWG is a closed format exclusive to Autodesk products. The ACadSharp library is user-friendly and offers functions for formatting and aligning text , such as aligning text (right, left, center, justify), vertical text alignment (top, middle, bottom), tab indentation, and so on. The ACadSharp library is available under the MIT-License.
Getting Started with ACadSharp
The recommended way to install ACadSharp is using NuGet. Please use the following command a smooth installation.
Install ACadSharp via NuGet
NuGet\Install-Package ACadSharp -Version 1.4.0-alpha
You can also install it manually; download the latest release files directly from GitHub repository.
Generate AutoCAD DXF/DWG Files via .NET Library
The ACadSharp library has provided complete support for creating and editing CAD DXF & DWG diagrams inside Python applications. It enables software developers create a simple and valid DXF & DWG diagrams with simple entities right now. Work on complex diagram is in progress and will be implemented soon. Developers can write ASCII as well as Binary DXF files with ease.
How to Create ASCII & Binary DXF File via C# .NET Library ?
namespace ACadSharp.Examples
{
public static class WriterExamples
{
///
/// Write a ascii dxf file
///
///
///
public static void WriteAsciiDxf(string file, CadDocument doc)
{
using (DxfWriter writer = new DxfWriter(file, doc, false))
{
writer.OnNotification += NotificationHelper.LogConsoleNotification;
writer.Write();
}
}
/// Write a binary dxf file
///
///
public static void WriteBinaryDxf(string file, CadDocument doc)
{
using (DxfWriter writer = new DxfWriter(file, doc, true))
{
writer.OnNotification += NotificationHelper.LogConsoleNotification;
writer.Write();
}
}
}
}
Manage Entities in CAD Model via C# .NET API
The open source ACadSharp library gives software developers the capability to handle AutoCAD model entities inside their own Python applications. The library has provided several important features for working with model entities, such as Get all the entities in the model, create new entities and add them into the drawing, access and modify entity properties and so on.
How to Get All Entities in the CAD Model via C# .NET ?
///
/// Get all the entities in the model
///
///
///
public static IEnumerable GetAllEntitiesInModel(string file)
{
CadDocument doc = DwgReader.Read(file);
// Get the model space where all the drawing entities are
BlockRecord modelSpace = doc.BlockRecords["*Model_Space"];
// Get all the entities in the model space
return modelSpace.Entities;
}
Access & Read AutoCAD DXF/DWG Files via .NET API
The open source ACadSharp library allows software developers to load and read AutoCAD DXF as well as DWG Files inside their own .NET applications with just a couple of lines of code. To access and read a file first you need to provide the complete path to the DXF as well as DWG Files. Please note that the some modules of DXF/DWG readers are not yet fully implemented and needs further improvement. The NotificationHandler will send a message to inform about the objects that could not be readed or any other error in the process.
How to Read DXF and DWG Files using C# .NET Library?
namespace ACadSharp.Examples
{
public static class ReaderExamples
{
/// Read a dxf file
/// dxf file path
public static void ReadDxf(string file)
{
using (DxfReader reader = new DxfReader(file, NotificationHelper.LogConsoleNotification))
{
CadDocument doc = reader.Read();
}
}
/// Read a dwg file
/// dwg file path
public static void ReadDwg(string file)
{
using (DwgReader reader = new DwgReader(file, NotificationHelper.LogConsoleNotification))
{
CadDocument doc = reader.Read();
}
}
}
}