1
|
9687 Views
|
4 Replies
|
2 Total Likes
View groups...
Share

# 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}}] //   GraphicsExport["polygon.dxf", polygon];Import["polygon.dxf"]
4 Replies
Sort By:
Posted 11 years ago
 Hi David,that is interesting.polygon =  Polygon[{{0, 0}, {0, 2}, {3, 2}, {3, 5}, {4, 5}, {4, 0}, {0, 0}}] // GraphicsExport["polygon.dxf", polygon, "GraphicsComplex"];data2 = Import["polygon.dxf"] data2 // FullFormgivesAs you can see, it converts the shape into triangles. If I take that manually apart the structure looks like this: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 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:http://forums.wolfram.com/mathgroup/archive/2011/Oct/msg00133.html
Posted 11 years ago
 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"];  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:loaddxf[name_String] := Graphics3D[    Polygon[Join[#[[1, 1]],       Table[#[[k, 1, 3]], {k, 2, Length[#]}]]]] & @   Import[name, "PolygonObjects"]Thenloaddxf["polygon3d.dxf"]should work.M.
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.Best,David
Posted 11 years ago
 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/I 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] := 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.