6
$\begingroup$

I wrote all code and there're no errors in code. Result of code is like first picture(left). But I can't Import that structure. The result of import stl file is second one(right one). How can I import it?(i think it's because i used table at that part)

enter image description here enter image description here

Code is here

repeatingUnit = Hexahedron[
   (*bottom*){{-2, -2, 0}, {-2, 2, 0}, {2, 2, 0}, {2, -2, 0},
    (*top*){-3, -3, 3}, {-3, 3, 3}, {3, 3, 3}, {3, -3, 3}}];

a = Graphics3D[
   Table[
    GeometricTransformation[
     repeatingUnit,
     TranslationTransform[{0, 0, n}]
     ], {n, 0, 21, 3}], Axes -> True];
v = {{-2, -2, 0}, {-2, 2, 0}, {2, 2, 0},
   {2, -2, 0}, {-3, -3, -12}, {-3, 3, -12}, {3, 3, -12}, {3, -3, -12}};
i = {{1, 2, 3, 4}, {1, 2, 6, 5}, {2, 3, 7, 6}, {3, 4, 8, 7}, {4, 1, 5,
     8}, {5, 6, 7, 8}};
b = Graphics3D[{GraphicsComplex[v, Polygon[i]]}, Axes -> True];
v2 = {{-1, -1, 25}, {-1, 1, 25}, {1, 1, 25}, {1, -1, 25}, {-1.7, -1.7,
     27.5}, {-1.7, 1.7, 27.5}, {1.7, 1.7, 27.5}, {1.7, -1.7, 27.5}};
i2 = {{1, 2, 3, 4}, {1, 2, 6, 5}, {2, 3, 7, 6}, {3, 4, 8, 7}, {4, 1, 
    5, 8}, {5, 6, 7, 8}};
c = Graphics3D[{GraphicsComplex[v2, Polygon[i2]]}, Axes -> True];
d = Graphics3D[Cylinder[{{0, 0, 27.5}, {0, 0, 31}}, 1/4]];
e = Graphics3D[Cylinder[{{0, 0, 31}, {0, 0, 33}}, 1/8]];
f = Graphics3D[Cuboid[{1, -1, 24}, {-1, 1, 25}]];
gj = Show[a, b, c, d, e, f]


Export["building.stl", gj]
Import["building.stl"]
$\endgroup$
5
  • 2
    $\begingroup$ what is your stl file and where is your code? $\endgroup$
    – Harry
    Aug 22, 2015 at 3:39
  • $\begingroup$ my stl file is in document folder, and I updated my code $\endgroup$
    – 유민우
    Aug 22, 2015 at 4:51
  • $\begingroup$ @Harry was hinting that you should upload your *.stl file somewhere so that potential helpers can help you better. $\endgroup$ Aug 22, 2015 at 6:18
  • $\begingroup$ Interesting enough, we can export and import just one Hexahedron at a time (which means that you could probably build a code with automatic multiple exports and imports). If you try to export only a, you receive an error saying that STL export is not implement for Graphics 3D, which is interesting since it omits that message when adding other Graphics3D, or exporting just b etc. I think this might be a "limitation" of export specifically with Hexahedron... $\endgroup$
    – P. Fonseca
    Aug 22, 2015 at 9:26
  • $\begingroup$ @유민우 If my answer below is acceptable to you and solves your problem, please consider accepting it formally by clicking on the grey triangle next to the question. $\endgroup$
    – MarcoB
    Aug 24, 2015 at 15:28

1 Answer 1

7
$\begingroup$

Exporting a 3D graphic that contains more than one Hexahedron object doesn't seem to work. The problem seems to stem from the fact that Export calls DiscretizeGraphics on the Graphics3D object, and DiscretizeGraphics can't handle the input. Both Export and ExportString work (i.e. fail) in the same way:

ExportString[Graphics3D[{Hexahedron[], Hexahedron[]}], "STL"]

DiscretizeGraphics::rnimpl: The function DiscretizeGraphics is not implemented for . >>

Export::type: Graphics3D cannot be exported to the STL format. >>

$Failed

Unfortunately, when the same happens within a call to Export with a more complex Graphics3D input, the system fails silently, and just returns whatever part of the original input it was able to process. This is what the OP observed.


A solution to this is not to use Hexahedron primitives in the construction of the model. In fact, the OP already had a primitive similar to the desired repeating unit coded as a Polygon object which exported fine.

In the following I will use the OP's definitions for b, c, d, e, f. I can then redefine the repeating unit of the building model a using a simple Polygon:

vrep = {
         (* vertices on bottom face*)
         {-2, -2, 0}, {-2, 2, 0}, {2, 2, 0}, {2, -2, 0}, 
         (* vertices on top face*)
         {-3, -3, 3}, {-3, 3, 3}, {3, 3, 3}, {3, -3, 3}
       };

irep = {
         {1, 2, 3, 4}, 
         {1, 2, 6, 5}, 
         {2, 3, 7, 6}, 
         {3, 4, 8, 7}, 
         {4, 1, 5, 8}, 
         {5, 6, 7, 8}
       };

a = Graphics3D[
      Table[
         GeometricTransformation[
            GraphicsComplex[vrep, Polygon[irep]],
            TranslationTransform[{0, 0, n}]
         ],
         {n, 0, 21, 3}
      ],
      Axes -> True
    ];

Once we have this new definition, we can use the rest of your code. The result is unchanged within Mathematica. The big difference, however, is the fact that now Export to an STL file seems to work!

gj = Show[a, b, c, d, e, f];
Export["building.stl", gj]; 

GraphicsRow[{gj, Import["building.stl"]}, ImageSize -> Full]

Mathematica graphics and STL input

$\endgroup$
1
  • $\begingroup$ So... Is your conclusion that this should be tagged as Bug and reported to WR? If someone does it (the reporting, I mean; the tag is easy to check...), please announce it. $\endgroup$
    – P. Fonseca
    Aug 23, 2015 at 9:38

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.