# Problem with DXF export / import

**URL:** <https://community.wolfram.com/t/problem-with-dxf-export-import/1604>\
**Category:** Questions\
**Tags:** graphics-and-visualization, import-and-export\
**Created:** [February 26, 2014, 9:58pm UTC](https://community.wolfram.com/t/problem-with-dxf-export-import/1604 "2014-02-26T21:58:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlkeith](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/dlkeith/32/31494_2.png) [@dlkeith](https://community.wolfram.com/u/dlkeith)\
**Post date:** [February 26, 2014, 9:58pm UTC](https://community.wolfram.com/t/problem-with-dxf-export-import/1604/1 "2014-02-26T21:58:56Z")

</div>

Can anyone explain this?

```auto
polygon = 
 Polygon[{{0, 0}, {0, 2}, {3, 2}, {3, 5}, {4, 5}, {4, 0}, {0, 0}}] // 
  Graphics

```

 ![polygonproblem1.png](https://global.discourse-cdn.com/wolfram/original/3X/6/9/694cb54c822c5ac5e92774c37d0412317e00156f.png)

```auto
Export["polygon.dxf", polygon];
Import["polygon.dxf"]

```

 ![9723polygonproblem2.png](https://global.discourse-cdn.com/wolfram/original/3X/5/8/589e27c27774d1fae6bd16794edec29037f8d4e9.png)

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [February 26, 2014, 10:42pm UTC](https://community.wolfram.com/t/problem-with-dxf-export-import/1604/2 "2014-02-26T22:42:57Z")

</div>

Hi David,

that is interesting.

```auto
polygon = 
 Polygon[{{0, 0}, {0, 2}, {3, 2}, {3, 5}, {4, 5}, {4, 0}, {0, 0}}] // Graphics

Export["polygon.dxf", polygon, "GraphicsComplex"];
data2 = Import["polygon.dxf"] 

data2 // FullForm

```

gives

 ![out.jpg](https://global.discourse-cdn.com/wolfram/original/2X/a/a4204a5def9caef43d2fcf2900d5bfd266e28067.jpeg)

As you can see, it converts the shape into triangles. If I take that manually apart the structure looks like this:

```auto
Show[{Graphics3D[{Polygon[
     List[List[0, 0, 0], List[0, 2., 0], List[3., 2., 0]]], 
    Polygon[List[List[0, 0, 0], List[3., 2. , 0], List[3., 5., 0]]], 
    Polygon[List[List[0, 0, 0], List[3., 5., 0], List[4., 5., 0]]], 
    Polygon[List[List[0, 0, 0], List[4., 5., 0], List[4., 0, 0]]], 
    Polygon[List[List[0, 0, 0], List[4., 0, 0], List[0, 0, 0]]]}]}]

```

or

 ![ImageReconstruct.jpg](https://global.discourse-cdn.com/wolfram/original/3X/5/0/50f2d4dec82711a3269b22e7f1012e803950ed7c.jpeg)

That shows what happens, but not exactly why it happens. The imported file (apart from being three dimensional instead of two dimensional as the original), appears to use the first point {0,0,0} always as the starting point of the vertex, and then uses sequences of two consecutive vertices for the polygons.

I’ll check whether some nice option fixes that.

M.

PS: Here’s a related post:

> **[MathGroup Archive: October 2011 \[00133\]](https://forums.wolfram.com/mathgroup/archive/2011/Oct/msg00133.html)**

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [February 26, 2014, 11:00pm UTC](https://community.wolfram.com/t/problem-with-dxf-export-import/1604/3 "2014-02-26T23:00:07Z")

</div>

Dear David,

I know that this “solution” is embarrassing, but…

```auto
polygon = 
 Polygon[{{0, 0}, {0, 2}, {3, 2}, {3, 5}, {4, 5}, {4, 0}, {0, 0}}] // Graphics

Export["polygon3d.dxf", polygon];
data = Import["polygon3d.dxf", "PolygonObjects"];

Graphics3D[
 Polygon[Join[data[[1, 1]], 
   Table[data[[k, 1, 3]], {k, 2, Length[data]}]]]]

```

As I said: embarrassing, but it appears to work. If you prefer you can define a function to import the dxf file:

```auto
loaddxf[name_String] := 
Graphics3D[
    Polygon[Join[#[[1, 1]], 
      Table[#[[k, 1, 3]], {k, 2, Length[#]}]]]] & @ 
  Import[name, "PolygonObjects"]

```

Then

```auto
loaddxf["polygon3d.dxf"]

```

should work.

M.

---

<div class="post-metadata">

**Author:** ![dlkeith](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/dlkeith/32/31494_2.png) [@dlkeith](https://community.wolfram.com/u/dlkeith)\
**Post date:** [February 26, 2014, 11:37pm UTC](https://community.wolfram.com/t/problem-with-dxf-export-import/1604/4 "2014-02-26T23:37:28Z")

</div>

Thank you, Marco.

This is really part of a larger issue. I was trying to generate DXF files which could be read by another application -- Comsol Multiphysics -- into a 2D workplane. If I generate a simple polygon formed with a closed sequence of 2D lines, Comsol imports it fine. But if I export a file containing a Mathematica rectangle graphic, or a disk graphic, then the Comsol import attempt results in a error “The file contains no geometry objects of the requested type.”

I don’t have problems with this in general, so I got to wondering if Mathematica could even import what it itself had exported. -- It appears not.

I open the DXF file with Wordpad and it contains 3D faces. For Comsol, DXF is a 2D format. I don’t know what Wolfram had in mind here, but it would be nice if 2D objects could be exported in a 2D format. Mathematica does not support any of the standard 3D exchange formats -- IGES, STEP, SAT, Parasolid.

Best,  
David

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [February 27, 2014, 12:48am UTC](https://community.wolfram.com/t/problem-with-dxf-export-import/1604/5 "2014-02-27T00:48:28Z")

</div>

Dear David,

yes, there seem to be some issues with the Export/Import commands here. Some are known to the technical support:  
[[http://forums.wolfram.com/student-support/topics/27472/](http://forums.wolfram.com/student-support/topics/27472/)

I]([http://forums.wolfram.com/student-support/topics/27472/](http://forums.wolfram.com/student-support/topics/27472/)) am afraid that I don’t know very much about 3D formats or Comsol Multiphysics. I have used a kinect sensor and third party software to scan 3D objects and import them into Mathematica, which seemed to work just fine.

I know that this does not solve your problem at all, but obviously we can modify the custom import function to import the dxf file that Mathematica exported as 3D, so that we obtain a 2D object (in Mathematica).

```auto
loaddxf2D[name_String] := 
 Graphics[Polygon[
   Transpose[
    Drop[Transpose[
      Join[#[[1, 1]], Table[#[[k, 1, 3]], {k, 2, Length[#]}]] & @ 
       Import[name, "PolygonObjects"]], -1]]]]

```

You are of course right that it would be nice if 2D would be exported as 2D.

There are free 3D to 2D dxf converters available online. Of course, that does not solve the direct export issue within Mathematica.

M.
