A technical application can host the control as its drawing surface. The control reads the file, draws it in the units of the drawing, and returns the point under the pointer, the entity nearest to a click, and the entities inside a rectangle. The host program uses those values for quoting, inspection, nesting, fabrication and printing.

The drawing

ReadDXF, ReadDWG and the DXF document

ReadDXF and ReadDWG replace the current drawing and display it. The DXF property is the document: entities, layers, blocks and drawing variables. WriteDXF and WriteDWG save that document, so the application can open a customer file, change it and return a DXF or DWG.

dxfReaderNETControl1.ReadDXF(@"C:\jobs\part.dxf");
foreach (Layer layer in dxfReaderNETControl1.DXF.Layers) { // layer.Name, layer.IsVisible }

Coordinates

CoordsToWorld and WorldToCoords

CoordsToWorld converts a pixel of the control into a point in drawing units. WorldToCoords does the opposite, so a computed point can be shown at the right place on screen. DXF.ToFormattedUnit formats a length with the precision stored in the drawing. ShowDrawingUnits opens the dialog for length and angle units: decimal, engineering, architectural, fractional, scientific, degrees, gradians and radians.

Vector2 world = dxfReaderNETControl1.CoordsToWorld(e.X, e.Y);
string text = dxfReaderNETControl1.DXF.ToFormattedUnit(world.X);

Selection

GetEntity and GetEntities

GetEntity returns the entity nearest to a point in drawing units. GetEntities returns the entities inside a rectangle defined by two corners. With HighlightEntityOnHover the entity under the pointer is emphasized before the user clicks.

MethodUse in the application
GetEntity Identify the part, hole or contour the user clicked
GetEntities Collect the geometry inside a window, for a batch operation
HighlightEntityOnHover Show which entity will be picked
Vector2 point = dxfReaderNETControl1.CoordsToWorld(e.X, e.Y);
EntityObject entity = dxfReaderNETControl1.GetEntity(point);
List<EntityObject> inside = dxfReaderNETControl1.GetEntities(corner1, corner2);

Precise points

ObjectOsnapMode

ObjectSnap turns object snap on. ObjectOsnapMode chooses the points the pointer locks to. Several modes are combined with a bitwise OR. ObjectOsnapTypeFlags.None clears them.

ObjectOsnapTypeFlagsLocks to
Endpoint End points of lines and arcs, and polyline vertices
Midpoint Midpoint of a line, an arc or a polyline segment
Center Center of a circle, an arc or a polyline arc
GeometricCenter Geometric center of a polyline or a 2D spline
Quadrant The four quadrant points of a circle or an ellipse
Intersection Intersection of two entities
Insertion Insertion point of a block, a text or an image
Perpendicular The perpendicular point on the entity
Tangent The tangent point on a circle, an arc or an ellipse
Nearest The nearest point on the entity
Node A point entity
Vertex The closest vertex of a polyline
dxfReaderNETControl1.ObjectSnap = true;
dxfReaderNETControl1.ObjectOsnapMode = ObjectOsnapTypeFlags.Endpoint | ObjectOsnapTypeFlags.Midpoint | ObjectOsnapTypeFlags.Intersection;

Area and perimeter

FindClosedAreaData

MathHelper.FindClosedAreaData reads a set of entities and returns the outer perimeter, the outer area, the total length and area of the holes, and the number of inner contours. The filled area is the outer area minus the inner area. An estimating, coating or nesting program uses these numbers directly, and ShowFilledAreas paints the recognized regions on the drawing.

double externalLength, externalArea, internalLength, internalArea; int holes;
bool found = MathHelper.FindClosedAreaData( dxfReaderNETControl1.DXF.Entities, out externalLength, out externalArea, out internalLength, out internalArea, out holes);
double filled = externalArea - internalArea;

Dimensions

Dimensions written into the drawing

The control adds the dimensions a technical drawing needs. Each method takes the measured geometry, an offset or a position for the dimension line, and an optional dimension style and layer.

MethodWhat it measures
AddLinearDimension Horizontal, vertical or rotated distance between two points
AddAlignedDimension Distance along the direction of two points or a line
AddAngularDimension Angle between two lines, or the angle of an arc
AddRadialDimension Radius of a circle or an arc
AddDiametricDimension Diameter of a circle or an arc
AddArcLengthDimension Length of an arc
AddLeader A leader with an annotation
dxfReaderNETControl1.AddLinearDimension(startPoint, endPoint, 10);
dxfReaderNETControl1.AddRadialDimension(circle, 15);

Interactive input

Rubber-band feedback

While the user picks points, the control can draw a temporary line, rectangle, circle, arc, polygon or dimension with ShowRubberBandLine, ShowRubberBandBox, ShowRubberBandCircle, ShowRubberBandArc, ShowRubberBandPolygon and ShowRubberBandLinearDimension. The temporary figure follows the pointer. When the input is complete, the application stores the real entity, for example with AddLine.

dxfReaderNETControl1.ShowRubberBandLine(anchor, current);
dxfReaderNETControl1.AddLine(anchor, current);

Fabrication files and models

NC1, STEP, IFC and OBJ

The same surface displays the files a technical workflow already uses. Each read method replaces the current drawing with the geometry of the file.

MethodFileWhat the control produces
ReadNC1 NC1, starting with the ST block The plate geometry. ShowDimensions adds dimensions. ShowFilledArea fills the inner region
ReadSTEP STEP AP214 / AP203 Edge curves as lines, circles and 3D polylines, grouped by part name
ReadIFC IFC, IFCZIP One mesh per product, a layer per class, groups by building storey
ReadOBJ Wavefront OBJ The vertices and faces of the mesh
dxfReaderNETControl1.ReadNC1(@"C:\jobs\plate.nc1", true, true);

Print and exchange

Plot, Image and WriteSVG

Plot sends the current view to a printer. PlotPreview draws it into a PrintPreviewControl. ShowPlotSettings opens the plot dialog. The Image property is the bitmap of the view, ready to archive or to place in a report. WriteSVG writes the drawing for a page that has to stay vectorial. PlotRendering chooses color, gray scale or monochrome output.

dxfReaderNETControl1.PlotRendering = PlotRenderingType.Monochrome;
dxfReaderNETControl1.Plot();
dxfReaderNETControl1.WriteSVG(@"C:\jobs\part.svg");