Manifold Geometry // Многообразная Геометрия

Open-source DXF export

/ Просмотров: 846

You know what? There is an open-sourced solution for DXF export coming from FreeCAD. For those who are not familiar with this awesome project, here is a short talk given by the FreeCAD's active contributors at FOSDEM'20.

Their DXF export consists of two parts:

  1. Translation of OpenCascade's B-rep entities to DXF entities.
  2. Serialization to file.

The serialization was done by Dan Heeks and published in sources here: https://github.com/danheeks/dxfconv. In FreeCAD, there's a slightly adapted version of Dan's routine, which is a bit more coupled with FreeCAD's architecture. One might prefer Dan's vanilla version simply because it does not bring any dependencies (only standard C++ libs). I used the one from FreeCAD.

DXF generated by and imported back to FreeCAD.

There are quite some toolkits for DXF export that you can find on the web. Among such, there is ezdxf Python package, which looks well established and nicely documented. We are looking for a C++ package, though, so let's forget about Python for now.

FreeCAD's C++ DXF writer is pretty fast. For the sample sheet metal part taken from Rhino forum, it takes a fraction of a second. I run it through 1106 test files, and it never crashed or exceeded 0.5 sec on my ordinary laptop. However, some nuances are worth expanding on.

The first thing is not apparent and looks undocumented. Your flat pattern should reside in the XOY projection view. If not, the output drawing becomes a mess, especially when it comes to circles and arcs (they lose their expected locations). Therefore, the option of automatic shape relocation to the XOY plane is something we added.

Discretisation of splines in DXF R12.

Then, one should be careful about the format version. By default, FreeCAD exports to R12 format that does not support splines. Therefore, all freeform curves are discretized, and that takes a bit of extra time, not to mention the loss of accuracy and bigger file size. At the time being, FreeCAD (ver. 0.18) cannot read splines back, even those exported by itself. Hence, if you're looking for a highly interoperable option, then the lossy R12 version is probably better.

Missing spline curves in FreeCAD after reading DXF R14.

Not surprisingly, Autodesk DWG TrueView does not suffer from such an issue: all spline curves exported by FreeCAD are correctly recognized there. So R14 might be just fine unless you have a good reason to fall back to R12 with polylines.

Spline entities are alright in Autodesk's TrueView 2021.

If you choose to polygonize splines, the question of accuracy shortly arises. The algorithm uses the GCPnts_UniformAbscissa tool of OpenCascade for doing that. This tool generates a uniform distribution of points along a curve, where the arc length is a parameter specified by the client code.

Accurate approximation of splines.
Coarse approximation of splines.

Well, that's basically it. If you'd ever need a DXF writer for geometry without decorations, the C++ DXF writer of FreeCAD is definitely an option. The code is available in the asiAlgo_WriteDXF class of Analysis Situs. If you need some support on that matter, feel free to reach out.

Leave your comment

Имя и сайт используются только при регистрации

Выберите человечка с поднятой рукой!

При нажатии на картинку, Ваш комментарий будет добавлен.