This library can be used for reading CAD files (version 4). Currently it reads only HEADER
and GRAPHICS
sections. The SEMANTIC
sections is left unprocessed. Only CAD files v4 are supported!
Install with Nuget: Install-Package CADReader
.
Аdd a reference to CADReader
and then instantiate a new instance of CADFile
class:
using CAD;
using CAD.Entity;
using CAD.Geometry;
using CAD.Nomenclature;
...
// read a CAD file
CADFile file = new CADFile("path/to/cad/file");
file.ReadFile(Encoding...);
// check log message
file.Log;
// get CAD file metadata
CADFileInfo info = file.FileInfo;
// access all layers
List<CADLayer> layers = file.Layers;
// or specific layer
CADLayer cadaster = file[CADLayerType.CADASTER];
// access entities
CADPoint point = cadaster.Entities[0] as CADPoint;
// access entity's geometry
Point geometry = point.Geometry as Point;
Following entities are described in CAD format and are supported by this library:
CADLayer
- defines a nested section in theGRAPHICS
section, grouping 1 or more graphicsCADPoint
- defines point graphics - either points from a geodetical network or polylines.CADLine
- defines line geometriesCADContour
- defines polygon geometriesCADSymbol
- defines point symbolsCADText
- defines texts
Each CADLayer
contains graphics and provides methods for searching using the spatial index, in which all graphics are inserted. Each layer has its separate spatial index created.
You can provide a filter function and search for graphics, satisfying your filter:
// search by entity type
List<ICADEntity> pointEntities = layer
.Search(i => i is CADPoint);
// search by CAD ID
string cadID = "6849.210";
ICADEntity result = layer.Search(i =>
{
if (i is CADContour contour && contour.CADId.Equals(cadID))
return true;
return false;
}).FirstOrDefault();
You can search for all graphics within the specified extent:
// create the search extent
Extent envelope = new Extent(631.362, 1553.444, 638.741, 1561.818);
// search for graphics
List<ICADEntity> results = layer.Search(envelope);
Extent
- used as search geometry when running spatial queries within layersPoint
- geometry representation of point graphics likeCADPoint
Polyline
- geometry representation of line graphics likeCADLine
Polygon
- geometry representation of polygon graphics likeCADContour
Contains additional classes and enumerations with code/value pairs.