/Linq2Acad

Primary LanguageC#MIT LicenseMIT

Linq2Acad

A library that aims to simplify AutoCAD .NET addin code. Available for AutoCAD 2015 and later.

Overview

Getting started

Linq2Acad is a library that aims to simplify AutoCAD .NET addin code. It should be a more intuitive API for working with the drawing database, making the learning curve for beginners less steep.

As a simple example, let's print all layer names using Linq2Acad:

using (var db = AcadDatabase.Active())
{
  var layerNames = new List<string>();
  
  foreach (var layer in db.Layers)
  {
    layerNames.Add(layer.Name);
  }
  
  MessageBox.Show($"Layers: {string.Join(", ", layerNames)}.");
}

Or, let's delete all BlockReferences from the model space:

using (var db = AcadDatabase.Active())
{
  foreach (var br in db.ModelSpace
                       .OfType<BlockReference>()
                       .UpgradeOpen())
  {
    br.Erase();
  }
}

This code shows how to import a block from a DWG file into the active document:

using (var sourceDb = AcadDatabase.OpenReadOnly(@"C:\Blocks\Block.dwg"))
using (var targetDb = AcadDatabase.Active())
{
  var block = sourceDb.Blocks
                      .Element("My_Block_V8");
  targetDb.Blocks
          .Import(block);
}

More code samples (in C# and VB.NET) can be found here.

NuGet package

UPDATE: Version 1.0.0 of Linq2Acad is now available on NuGet! There is a dedicated NuGet package for each AutoCAD version, the packages are named Linq2Acad-20xx (see nuget.org).

How to upgrade from source code to Nuget

  1. Remove your existing Linq2Acad PROJECT completely from your existing Visual Studio solution. (You should see a lot of red squiggly lines.)
  2. Install the Nuget Packages.

(If you add Nuget while already having a Linq2Acad project there, and THEN you subsequently remove the latter project - you might have a lot of problems.)

Breaking changes not reflected in version updates

Beginning with the Nuget release of version 1.0.0, Linq2Acad is released in accordance with the rules of semantic versioning. Previous to that, there have been breaking changes to the API that were not reflected in the API's version number. The changes in question can be found here.

API documentation

The best entry point into the API documentation is the class AcadDatabase. An overview of all classes can be found here.

Code samples

Code samples in C# and VB.NET can be found here.

How it works?

This blog series discusses:

  • the original problem this library seeks to solve,
  • the design / implementation decisions involved in deriving the API.

Contributing

Please contribute to this project by

  • opening an issue if you found a bug or have a feature request
  • creating a pull request if you want to help extending the library

For those with graphic design abilities: it would be nice to have a Linq2Acad logo.

License

Linq2Acad is licended unter the MIT License (MIT).