Message Boards Message Boards

4 Replies
2 Total Likes
View groups...
Share this post:

Problem with DXF export / import

Posted 11 years ago
Can anyone explain this?
polygon =
Polygon[{{0, 0}, {0, 2}, {3, 2}, {3, 5}, {4, 5}, {4, 0}, {0, 0}}] //
Export["polygon.dxf", polygon];

POSTED BY: David Keith
4 Replies
Hi David,

that is interesting.
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


As you can see, it converts the shape into triangles. If I take that manually apart the structure looks like this:
     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]]]}]}]


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.


PS: Here's a related post:
POSTED BY: Marco Thiel
Dear David,

I know that this "solution" is embarrassing, but...
 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"];
  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:
loaddxf[name_String] :=
    Polygon[Join[#[[1, 1]],
      Table[#[[k, 1, 3]], {k, 2, Length[#]}]]]] & @
  Import[name, "PolygonObjects"]

should work.

POSTED BY: Marco Thiel
Posted 11 years ago
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.

POSTED BY: David Keith
Dear David,

yes, there seem to be some issues with the Export/Import commands here. Some are known to the technical support:

 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).
loaddxf2D[name_String] :=
      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.

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract