C#netDxf analysis of DXF in CAD

After receiving the DXF file parsing task, I found it on the universal Internet with everything. If it's not smooth, I can't find what I want by reading more than 10 blog posts and downloading more than 10 examples. It's a toss.

The following is the analysis of DXF file format, which can also be said to be the extraction of DXF data. After obtaining DXF data, you can love whatever you like.

Data extraction must have a standardized data format. If you find the official documents, you basically don't need to look at other materials. Just look at the following links.

Official description of DXF format:http://docs.autodesk.com/ACD/2011/CHS/filesDXF/WSfacf1429558a55de185c428100849a0ab7-5f35.htm

If you know the data format, is it finished?

Of course you can, but you have to have 10 days and half a month to study it in depth. Although the straight line is very simple, there are many types of straight lines, such as spline curve, multi segment and so on. To tell you the truth, even the liver can be made. However, it is easy to miss some details, resulting in incomplete analysis. Therefore, liver is not recommended. Of course, before I am familiar with netDxf, I do have liver for a few days, reading and judging line by line. Very disciplined,,,

netDxf is an open source DXF file parsing tool. The source code link is as follows:

Source code of parsing tool netDxf:https://github.com/haplokuon/netDxf

This website is in English, so scared!!!

Don't be afraid. No matter the black cat or the white cat catches the mouse, it's a good cat. I'm afraid it's a kidney. As long as I can download the source code and get the DLL, everything else is fine.

There are three steps as follows:


2,Downlod ZIP

3. Wait for the download to complete

There is another way to be lazy. Use NuGet, right-click the project, and press the following picture step by step. Of course, there must be an Internet. If there is no Internet, this method is ignored.

Since I have downloaded it, I don't click on it (click the position of 5), so "6" in the figure above is blank. After clicking 5, there will be a download button. After clicking download, just think quietly and wait for the loading to be completed, so I can use it directly in the code.

The above is inconsistent with the title. Too much irrelevant?

But after the meeting, DXF parsing is really, take whatever you want. I didn't believe it at first. Let's see:

The preparatory work is not much to say:

1. Load DXF file: (one line of code)

DxfDocument dxfDocument = DxfDocument.Load(dxfFileFullPath);

dxfFileFullPath: the full path of the DXF file

2. What do you want? Circle, spline, dimension?

2.1. Data of analytic circle:

2.1.1 open the official document website and find the circle. The graphic object is the ENTITIES section

2.1.2 read the parameters of the circle through netDxf tool

IEnumerable<netDxf.Entities.Circle> circle = 
foreach (netDxf.Entities.Circle item in circle)
    item.Center.X.ToString();//Center X
    item.Center.Y.ToString();//Center Y
    item.Radius.ToString();//Circle radius

For all parameters of the Circle, open source F12 to view the Circle, such as:

namespace netDxf.Entities
    public class Circle : EntityObject
        public Circle();
        public Circle(Vector3 center, double radius);
        public Circle(Vector2 center, double radius);

        public Vector3 Center { get; set; }
        public double Radius { get; set; }
        public double Thickness { get; set; }

        public override object Clone();
        public List<Vector2> PolygonalVertexes(int precision);
        public LwPolyline ToPolyline(int precision);
        public override void TransformBy(Matrix3 transformation, Vector3 translation);

2.2. Analyze SPLINE curve data: don't say too much. In the same way, see} SPLINE;

2.7. Obtain annotation: don't mention it. Look at DIMENSION in the same way;

DXF file parsing is not explained.

Here, whether DXF takes Whatever it wants, right, right, it should be right.


Tags: C#

Posted by SoulAssassin on Sun, 22 May 2022 07:31:32 +0300