Git Product home page Git Product logo

dxf-1's Introduction

IxMilia.Dxf

A portable .NET library for reading and writing DXF and DXB files. Clone and build locally or directly consume the NuGet package.

Build Status

Usage

Open a DXF file:

using System.IO;
using IxMilia.Dxf;
using IxMilia.Dxf.Entities;
// ...

DxfFile dxfFile;
using (FileStream fs = new FileStream(@"C:\Path\To\File.dxf", FileMode.Open))
{
    dxfFile = DxfFile.Load(fs);
}

foreach (DxfEntity entity in dxfFile.Entities)
{
    switch (entity.EntityType)
    {
        case DxfEntityType.Line:
            DxfLine line = (DxfLine)entity;
            // ...
            break;
        // ...
    }
}

Save a DXF file:

using System.IO;
using IxMilia.Dxf;
using IxMilia.Dxf.Entities;
// ...

DxfFile dxfFile = new DxfFile();
dxfFile.Entities.Add(new DxfLine(new DxfPoint(0, 0, 0), new DxfPoint(50, 50, 0)));
// ...

using (FileStream fs = new FileStream(@"C:\Path\To\File.dxf", FileMode.Create))
{
    dxfFile.Save(fs);
}

Compatibility

Reading Files

This library should be able to open any valid DXF file, including files produced by AutoCAD or anything using the Teigha libraries from the Open Design Alliance, including Microsoft Visio which uses older Open Design libraries.

Open Design Alliance (Teigha)

The Teigha libraries should be able to open anything produced by this library.

AutoCAD

AutoCAD is rather fussy with what it will accept as valid DXF, even though the official spec is rather loose. If you use this library to write a file that AutoCAD can't open, file an issue with the drawing (or a sample) that was produced by this library. I've found that AutoCAD compatibility can be greatly improved by doing the following:

// assuming `dxfFile` is a valid `DxfFile` object
dxfFile.Header.SetDefaults();
dxfFile.ViewPorts.Clear();
dxfFile.Save(...);

There are also some entity types that AutoCAD might not open when written by this library, specifically:

  • 3DSOLID (Dxf3DSolid)
  • ACAD_PROXY_ENTITY (DxfProxyEntity)
  • ATTRIB (DxfAttribute)
  • ATTDEF (DxfAttributeDefinition)
  • BODY (DxfBody)
  • DIMENSION (DxfAlignedDimension, DxfAngularThreePointDimension, DxfDiameterDimension, DxfOrdinateDimension, DxfRadialDimension, DxfRotatedDimension)
  • HELIX (DxfHelix)
  • LIGHT (DxfLight)
  • MTEXT (DxfMText)
  • REGION (DxfRegion)
  • SHAPE (DxfShape)
  • TOLERANCE (DxfTolerance)

And the following entities might not open in AutoCAD if written with missing information, e.g., a LEADER (DxfLeader) requires at least 2 vertices.

  • INSERT (DxfInsert)
  • LEADER (DxfLeader)
  • MLINE (DxfMLine)
  • DGNUNDERLAY (DxfDgnUnderlay)
  • DWFUNDERLAY (DxfDwfUnderlay)
  • PDFUNDERLAY (DxfPdfUnderlay)
  • SPLINE (DxfSpline)
  • VERTEX (DxfVertex)

Also note that AutoCAD doesn't seem to like R13 files written by IxMilia. For the greatest chance of compatibility, save the file as either R12 or the newest version possible (e.g., R2013 or R2010.)

Status

Support for DXF files is complete from versions R10 through R2014 EXCEPT for the following entities:

  • HATCH
  • MESH
  • MLEADER
  • SURFACE
  • TABLE
  • VIEWPORT

Building locally

Requirements to build locally are:

sudo apt-get install dotnet-sharedframework-microsoft.netcore.app-1.0.3

DXF Reference

Since I don't want to fall afoul of Autodesk's lawyers, this repo can't include the actual DXF documentation. It can, however contain links to the official documents that I've been able to scrape together. For most scenarios the 2014 documentation should suffice, but all other versions are included here for backwards compatibility and reference between versions.

R10 (non-Autodesk source)

R11 (differences between R10 and R11)

R12 (non-Autodesk source)

R13 (self-extracting 16-bit executable)

R14

2000

2002

2004

2005

2006

2007 (Autodesk's link erroneously points to the R2008 documentation)

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

Many of these links were compiled from an archive.org May 9, 2013 snapshot

The 2015-2019 spec can be downloaded for offline use via the ReferenceCollector.

dxf-1's People

Contributors

brettfo avatar lgrzywac avatar nzain 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.