A library that aims to simplify AutoCAD .NET plugin code. Available for AutoCAD 2015
and later.
Linq2Acad
is a library that aims to simplify AutoCAD .NET plugin code. It should be a more intuitive API for working with the drawing database, making the learning curve for beginners less steep.
using (var db = AcadDatabase.Active())
{
var layerNames = db.Layers.Select(l => l.Name);
MessageBox.Show(string.Join(", ", layerNames));
}
using (var db = AcadDatabase.Active())
{
foreach (var br in db.ModelSpace
.OfType<BlockReference>()
.UpgradeOpen())
{
br.Erase();
}
}
using (var sourceDb = AcadDatabase.OpenReadOnly(@"C:\Blocks\Shapes.dwg"))
using (var targetDb = AcadDatabase.Active())
{
var block = sourceDb.Blocks.Element("TRIANGLE");
targetDb.Blocks.Import(block);
}
var entityId = GetEntity("Pick an Entity");
var key = GetString("Enter key");
var str = GetString("Enter string to save");
// We first write the data (it is stored in the Entity's extension data)
using (var db = AcadDatabase.Active())
{
db.CurrentSpace
.Element(entityId)
.SaveData(key, str);
WriteMessage($"Key-value-pair {key}:{str} saved on Entity");
}
// Then we read it back
using (var db = AcadDatabase.Active())
{
var str = db.CurrentSpace
.Element(entityId)
.GetData<string>(key);
WriteMessage($"String {str} read from Entity");
}
using (var db = AcadDatabase.Active())
{
db.SummaryInfo.Author = "John Doe";
db.SummaryInfo.CustomProperties["CustomData1"] = "42";
}
using (var db = AcadDatabase.Active())
{
foreach (var xRef in db.XRefs
.Where(xr => xr.IsLoaded))
{
xRef.Reload();
}
}
More code samples (in C# and VB.NET) can be found here.
- Remove your existing
Linq2Acad
PROJECT completely from your existing Visual Studio solution. (You should see a lot of red squiggly lines.) - 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.)
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.
The best entry point into the API documentation is the class AcadDatabase. An overview of all classes can be found here.
This blog series discusses:
- the original problem this library seeks to solve,
- the design / implementation decisions involved in deriving the API.
See contributing documentation.
Linq2Acad is licended unter the MIT License (MIT).