I have the X and Y values for a curve in C# and I want them to be drawn in a dxf or dwg file format using the same C# project.
Is there a way to do that?
Thank you.
I have the X and Y values for a curve in C# and I want them to be drawn in a dxf or dwg file format using the same C# project.
Is there a way to do that?
Thank you.
A long time ago I wrote a DXF writer with VB.NET 2003, that I have converted to C#. It has methods for line, circle, arc, text, dimension, rectangle, polyline and points. You use it like this:
DxfMaker dxf = new DxfMaker();
float[,] points = new float[,]
{
{ 0, 10 },
{ 1, 12 },
{ 2, 17 },
{ 3, 14 },
{ 4, 9 }
};
int N = points.GetLength(0);
for (int i = 1; i < N; i++)
{
dxf.DXF_Line(
points[i - 1, 0], points[i - 1, 1], 0,
points[i, 0], points[i, 1], 0);
}
dxf.DXF_Save("curve.dxf");
The project with the source code is shared here. Caveat is because it was VB originally some of the numerical types are inconsistent (between float
and double
) by the results are good. Original code for DXF was taken from elsewhere (see comments) and adapted to my needs.
If you are generating data in C# the easiest way to the results in AutoCAD is to write a dxf file. The dxf file is a text file. Autodesk (maker of AutoCAD) publishes the dxf specification here. You will need some basic AutoCAD knowledge (blocks/layers/groups etc.) to understand the spec.