# Exporting several prisms (or Polyhedrons) to stl (with filled inner space)

I want to export hundreds of prisms to stl. And for this stl file to be 3D printable, its inner space must be filled.

I've tried two approaches to solve this problem. (just two prisms for a brief explanation)

1. The first one is using "Prisms" (https://reference.wolfram.com/language/ref/Prism.html)

As I ultimately want to make several prisms, I can make them with Graphics3D but cannot export them to stl at once.

twoprisms = Graphics3D[{Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 2, 0}}], Prism[{{1, 2, 1}, {0, 2, 0}, {2, 2, 0}, {1, 4, 1}, {0, 4, 0}, {2, 4, 0}}]}]
Export["twoprisms.stl", twoprisms]
1. The next approach is thickening polygons to prisms (Thick polygons in Graphics3D)

(This code is from @jVincent, not me)

normal[a_, b_, c_] := Normalize@Cross[a - b, c - b]
normal[a___] := Mean[normal @@@ Partition[{a}, 3, 1, 1]]
sides[bottom_, top_] := Polygon[Reverse@Join[#1, Reverse@#2]] & @@@ ({bottom, top} // Transpose // Partition[#, 2, 1, 1] &)
thicken[val_, t_: 0.1] := val /. Polygon[bottom_, ___] :> With[{top = (# + t normal @@ bottom) & /@ bottom}, {Polygon[Reverse@bottom], sides[bottom, top], Polygon[top]}]
initial = Graphics3D[{Polygon[{{1, 1, 0}, {1, 2, 0}, {2, 1, 0}}], Polygon[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}]}];
inital2 = thicken[initial, 0.3]
Export["inital.stl", initial]

This one can be exported to stl file. But it's hollow. (not 3D printable)

How can I make several filled prisms to stl file?

Here is another way try using ToElementMesh:

Needs["NDSolveFEM"]
twoprisms2 =
RegionUnion@{Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0,
2, 0}, {2, 2, 0}}],
Prism[{{1, 2, 1}, {0, 2, 0}, {2, 2, 0}, {1, 4, 1}, {0, 4, 0}, {2,
4, 0}}]};
mr = MeshRegion@
ToElementMesh[twoprisms2, MaxCellMeasure -> Infinity,
"MeshOrder" -> 1];
Export["testprism.stl", mr];

One possible advantage to the ToElementMesh approach is that the model should be watertight since it is used for FEM modeling.

# Extension to multiple prisms

To extend to the two prism case, remove the Graphics3D from initial so that it may be treated as a region. Then, use the following code:

initial = {Polygon[{{1, 1, 0}, {1, 2, 0}, {2, 1, 0}}],
Polygon[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}]};
initial2 = RegionUnion @@ Flatten[thicken[initial, 0.3]];
mr = MeshRegion@
ToElementMesh[initial2, MaxCellMeasure -> Infinity,
"MeshOrder" -> 1];
Export["twoprism.stl", mr];
Import["twoprism.stl"]

• Thank you! I'm trying to apply it to mine(with hundreds of Prisms) Commented Sep 10, 2020 at 2:14
• The prisms in my code are combined with Translate and Rotate functions. It seems RegionUnion is not working in this case... Commented Sep 10, 2020 at 2:23
• @dodo_nuna_2nd You need to apply RegionUnion to a flattened list of regions. Commented Sep 10, 2020 at 3:05
• Thank you! I think I can make it! Commented Sep 10, 2020 at 5:23

Update

Perhaps we can direct use BoundaryMeshRegion

Clear["*"];
bmr1 = BoundaryMeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {2, 1}, {2,
2}, {1, 2}}, Line[{{1, 2, 4, 1}, {3, 5, 6, 3}}]];
bmr2 = BoundaryMeshRegion[{{0}, {1}}, Point[{{1}, {2}}]];
RegionProduct[bmr1, bmr2];
Export["two.stl", %]

Original

twoprisms =
Region /@ {Prism[{{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2,
0}, {2, 2, 0}}],
Prism[{{1, 2, 1}, {0, 2, 0}, {2, 2, 0}, {1, 4, 1}, {0, 4, 0}, {2,
4, 0}}]} // RegionUnion

Export["twoprisms.stl", twoprisms]

first Update

Clear["*"];
data1 = {{1, 0, 1}, {0, 0, 0}, {2, 0, 0}, {1, 2, 1}, {0, 2, 0}, {2, 2,
0}};
data2 = {{1, 2, 1}, {0, 2, 0}, {2, 2, 0}, {1, 4, 1}, {0, 4, 0}, {2, 4,
0}};
sets = {Partition[data1, 3], Partition[data2, 3]}
Flatten[Complement[Union @@ sets, Intersection @@ sets], 1] //
Prism // Region
Export["newtwoprism.stl", %]
Import["newtwoprism.stl"]

Need to be updated...

• Same error. \ DiscretizeRegion::regpnd: A non-degenerate region is expected at position 1 of~ . Export::type: Region cannot be exported to the STL format. Commented Sep 10, 2020 at 0:50
• Thank you! But looks a little bit difficult to my actual code. Commented Sep 10, 2020 at 5:24