GithubHelp home page GithubHelp logo

killer9806 / linq2acad Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wtertinek/linq2acad

0.0 0.0 0.0 7.48 MB

A library that aims to simplify AutoCAD .NET plugin code

License: MIT License

C# 94.33% Batchfile 1.19% Visual Basic .NET 4.48%

linq2acad's Introduction

Linq2Acad

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

Overview

News

Linq2Acad-2024 is now available as a release candidate on NuGet. If you test it, please provide some feedback to the pull request.

Getting started

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.

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

using (var db = AcadDatabase.Active())
{
  var layerNames = db.Layers.Select(l => l.Name);
  MessageBox.Show(string.Join(", ", layerNames));
}

Linq2Acad makes it easy to 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\Shapes.dwg"))
using (var targetDb = AcadDatabase.Active())
{
  var block = sourceDb.Blocks.Element("TRIANGLE");
  targetDb.Blocks.Import(block);
}

You can easily store data on entities:

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");
}

You can use Linq2Acad to changes the summary info of the active document:

using (var db = AcadDatabase.Active())
{
  db.SummaryInfo.Author = "John Doe";
  db.SummaryInfo.CustomProperties["CustomData1"] = "42";
}

There's also a simple way to, for example, reload all loaded XRefs:

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.

Installation

NuGet packages

Linq2Acad is available on NuGet. There is a dedicated Linq2Acad package for each AutoCAD version. Simply add the package for your AutoCAD version to your C#/VB project in Visual Studio. Available packages:

Linq2Acad-2024
Linq2Acad-2023 Linq2Acad-2022
Linq2Acad-2021 Linq2Acad-2020
Linq2Acad-2019 Linq2Acad-2018
Linq2Acad-2017 Linq2Acad-2016
Linq2Acad-2015

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 Package

(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)

API documentation

The best entry point into the API documentation is the class AcadDatabase. An overview of all classes 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

We would love for you to contribute to Linq2Acad and help to make the life of AutoCAD plugin developers easier. We welcome ideas, suggestions and discussions to push the development forward. Implementation of bugfixes or new features are also always welcome. For details see the contributing guidelines.

License

Linq2Acad is licended unter the MIT License (MIT).

linq2acad's People

Contributors

benkoshy avatar bk224 avatar sanzoghenzo avatar wtertinek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.