2
$\begingroup$

I have exported a DXF file from Mathematica and I am trying to import it in AutoCAD.

The file that has been exported is output of a command like the following

g = Graph[vl, edges, 
 VertexCoordinates -> {v_ :> ({x[v], y[v]} /. solution)}, 
 EdgeWeight -> ew, VertexLabels -> Placed["Name", Center], 
 EdgeLabels -> {e_ :> Placed["EdgeWeight", .3]}, VertexSize -> .7, 
 VertexStyle -> Red] 

More details can be found in my previous post here

The following graph was exported from Mathematica using the command : Export["file.dxf", Show[Graph3D[g]]] enter image description here

The file obtained after export is shared here.

But when I try to open the file in AutoCAD, the drawing window in AutoCAD shuts.

Could someone look into this?

If this doesn't work, can I export in other formats?

EDIT: The solution suggested below doesn't work when the output is obtained as a result of the following command

g3d = Graph3D[vl, edges, 
  VertexCoordinates -> {v_ :> ({x[v], y[v], z[v]} /. solution3d)}, 
  EdgeWeight -> ew, VertexLabels -> Placed["Name", Center], 
  EdgeLabels -> {e_ :> Placed["EdgeWeight", .5]}, VertexSize -> .3, 
  VertexStyle -> Red, ImageSize -> Large]

I think the problem here is solution3d already as x,y,z coordinates in it. When I export the output to dxf using

Export["file.dxf", Show[Graph3D[g3d]]]

the exported dxf can't be imported in AutoCAD.

$\endgroup$

1 Answer 1

2
$\begingroup$

The DXF file you made isn't wrong, but it's in a different format than your original. Your original DXF was a set of lines in 3D. Here's how to make a simple DXF file from the answer's solution. Refer to the answer at Scaling the edge length of a graph to be equal to edge weight.

1) The solution from the answer has new 2D vertex coordinates. Get line data from the original DXF file.

solution = {x[1] -> 74.8765323341147, y[1] -> 38.338839560418336, 
  x[2] -> 123.40647961090141, y[2] -> 47.8708899668093, 
  x[3] -> 8.917284888177424, y[3] -> 2.766361654099819, 
  x[4] -> 45.00000011321871, y[4] -> 0.,
  x[5] -> 97.09834751979837, y[5] -> 73.57592753317832,
  x[6] -> 49.91286233087924, y[6] -> 60.18973414245018,
  x[7] -> 0., y[7] -> 24.999999734296512, 
  x[8] -> 13.634582696340212, y[8] -> 59.0724623077659, 
  x[9] -> 114.99999830823879, y[9] -> 24.99999745723544};
ld = Import["input.dxf","LineData"]
{{1,2}, {1,3}, {1,4}, {2,5}, {2,6}, {5,6}, {3,4}, {3,7}, {6,7}, {7,8}, {2,9}}

2) Change the 2D vertices from the solution to 3D by setting the z coordinate to zero. Create lines from the line data, ld, and the vertex coordinates, vd.

vd = Append[#, 0.] & /@ Partition[Values[solution], 2];
lines = Line[vd[[#]]] & /@ ld;

3) Make a 3D graphic of the lines and export to a DXF file.

g = Graphics3D[lines, Boxed -> False, ViewPoint -> Top]

lines displayed in 3D graphic

Export["output.dxf", g];
$\endgroup$
7
  • $\begingroup$ I could import the file into AutoCAD . Thanks a ton. Could you please let me know if it is possible to retain the edge labels and vertex labels in the dxf export? $\endgroup$
    – Natasha
    Apr 29, 2020 at 17:02
  • $\begingroup$ Yes, you can find how from Labeling a three-dimensional plot. For the vertex labels, check how order is used to place the numbers in the correct order. Instead of pos[[i]], vd[[i]] are the vertex coordinates. $\endgroup$
    – creidhne
    Apr 29, 2020 at 19:12
  • $\begingroup$ Could you please explain why g = Graphics3D[lines, Boxed -> False, ViewPoint -> Top, VertexLabels -> Automatic] doesn't work? $\endgroup$
    – Natasha
    Apr 30, 2020 at 2:36
  • $\begingroup$ And if I were to use this, labels = Table[Inset[Style["Label " <> ToString[i], Bold, 20], vd[[i]]], {i, Length@holes}]; what should go in place of holes? $\endgroup$
    – Natasha
    Apr 30, 2020 at 2:38
  • $\begingroup$ Edge lengths are obtained like this, edgeLengths = # -> Norm[Through[{x, y}@First[#]] - Through[{x, y}@Last[#]]] /. solution & /@ EdgeList[g3d]. Please suggest how this has to be addd to g. solution and g3d are from answer provided from previous post $\endgroup$
    – Natasha
    Apr 30, 2020 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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