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,...?

Link to DXF file:

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.

  • 3
    $\begingroup$ Do you have an example file? In any event: Import[filename, "GraphicsComplex"]. $\endgroup$ – J. M.'s ennui Jul 7 '16 at 9:56
  • 1
    $\begingroup$ 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. $\endgroup$ – Yves Klett Jul 7 '16 at 10:29
  • $\begingroup$ Added link to the DXF file $\endgroup$ – LCarvalho Jul 7 '16 at 16:20
  • 1
    $\begingroup$ Import["https://www.dropbox.com/s/nho1hty6ukzbnlz/Desenho%20para%20Importar%20no%20Mathematica.dxf?dl=1",{"DXF","Graphics3D"}] $\endgroup$ – Jason B. Jul 7 '16 at 16:53
  • $\begingroup$ Ok, but it is possible to convert this file dxf automatically in graphics as circles, lines, points,...? $\endgroup$ – LCarvalho Jul 7 '16 at 17:05

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


(* {"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:


Mathematica graphics

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


(* {{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

Mathematica graphics

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

Mathematica graphics

  • $\begingroup$ There is only the option of getting lines? And how could recognize as circle? $\endgroup$ – LCarvalho Jul 8 '16 at 16:42
  • 1
    $\begingroup$ 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. $\endgroup$ – Jason B. Jul 8 '16 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.