# Importing and manipulating DXF files

Assuming I have a DXF file containing circles, lines, rectangles, ...

It is possible to convert this file dxf automatically in graphics as circles, lines, points,...?

DXF file

I ask this question because I have several graphics on this type of format and would like to use them and to manipulate them into MMA.

• Do you have an example file? In any event: Import[filename, "GraphicsComplex"]. – J. M.'s ennui Jul 7 '16 at 9:56
• Possible in general, usually DXF elements are imported as 3D data. As mentioned by @J.M., without examples and more information we cannot help you any further than that. – Yves Klett Jul 7 '16 at 10:29
• Added link to the DXF file – LCarvalho Jul 7 '16 at 16:20
• Import["https://www.dropbox.com/s/nho1hty6ukzbnlz/Desenho%20para%20Importar%20no%20Mathematica.dxf?dl=1",{"DXF","Graphics3D"}] – Jason B. Jul 7 '16 at 16:53
• Ok, but it is possible to convert this file dxf automatically in graphics as circles, lines, points,...? – LCarvalho Jul 7 '16 at 17:05

If you look here, you get an idea where to start: DXF

url="https://www.dropbox.com/s/nho1hty6ukzbnlz/Desenho%20para%20Importar%20n‌​o%20Mathematica.dxf?dl=1";
Import[url,{"DXF","Elements"}]

(* {"BoundaryMeshRegion", "CoordinateTransform", "Graphics3D",
"GraphicsComplex", "LineData", "LineObjects", "MeshRegion",
"PlotRange", "PointData", "PointObjects", "PolygonData",
"PolygonObjects", "Region", "Summary", "VertexColors", "VertexData",
"ViewPoint"} *)


If you simply Import it without specifying the element, you get a MeshRegion:

Import[url,"DXF"]


But let's try to grab the graphics objects directly,

Import[url,
{"DXF",{"LineObjects","PointObjects","PolygonObjects"}}]

(* {{Line[{{63.,82.,0.},{87.,82.,0.}}],Line[<<1>>],<<3>>,Line[{<<1>>}],Line[{{43.4965,59.7512,0.},<<19>>,{106.504,59.7512,0.}}]},<<1>>,{}} *)


So your lines and points are all listed as 3D, but the third coordinate is always zero. So you can apply Graphics3D to it if you like,

Import[url, {"DXF", {"LineObjects", "PointObjects",
"PolygonObjects"}}] // Graphics3D


To convert it to 2D you can use a pattern replacement,

Import[url, {"DXF", {"LineObjects", "PointObjects",
"PolygonObjects"}}] //
Replace[#, {a_?NumericQ, b_?NumericQ, 0.} :> {a, b},
Infinity] & // Graphics


• There is only the option of getting lines? And how could recognize as circle? – LCarvalho Jul 8 '16 at 16:42
• So when it imports the file, each of the circles and lines are represented as a set of points. When I just double-clicked the file, LibreOffice opened it, and the circles look like circles instead of a series of lines like they do here. So maybe there is some kind of Bezier curve info included as well in the file but Mathematica can't access it. The available elements to import are at the top of this post - just points, lines, and polygons. To make them smoother curves you'll have to do some processing on them yourself I think. – Jason B. Jul 8 '16 at 16:46