# How to save in STL format for 3D printing?

I have the code of a spherical gyroid written in Mathematica and I am unable to save it in STL format. The image is shown in the figure below and the code is shown below. I need help with a code on how to save it as an STL file.

r = 2 Pi;
model = ContourPlot3D[
Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[x] == 0, {x, -r,
r}, {y, -r, r}, {z, -r, r},
RegionFunction -> ({x, y, z} \[Function] x^2 + y^2 + z^2 <= r^2),
Mesh -> None, PlotTheme -> "ThickSurface",
Method -> {"Extrusion" -> .3}]

• Export["output.stl", model] doesn't work? Nov 25, 2020 at 12:16
• Good evening sir, the code doesn't work, I will be grateful if you give me your own code. I have been stressing about this for two weeks now Nov 25, 2020 at 19:13

First remove the Box and Axes

r=2 Pi;
model = ContourPlot3D[Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[x] == 0, {x, -r,r}, {y, -r, r}, {z, -r, r},RegionFunction -> ({x, y, z} \[Function] x^2 + y^2 + z^2 <= r^2),Mesh -> None,PlotTheme -> "ThickSurface",Method -> {"Extrusion" -> .3}
, Axes -> False, Boxed -> False]


Now you might use the answer (thanks @Henrik Schumacher) of your own question from march2020 how to save a file in STL format

Export[…,DiscretizeGraphics[model]]

• thank you for the answer Sir, but here is the complete code, once I run it gives me an error...r = 2 Pi; model = ContourPlot3D[ Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[x] == 0, {x, -r, r}, {y, -r, r}, {z, -r, r}, RegionFunction -> ({x, y, z} [Function] x^2 + y^2 + z^2 <= r^2), Mesh -> None, PlotTheme -> "ThickSurface", Method -> {"Extrusion" -> .3}, Axes -> False, Boxed -> False, Export["a.stl", DiscretizeGraphics[model]]] Nov 25, 2020 at 19:06
• The code runs on v12 Windows 10. What errors occur? Nov 25, 2020 at 19:08
• I will be grateful if you send me your own code Sir, I have that windows version Nov 25, 2020 at 19:10
• Copy the three lines of code from my answer, quit your kernel and run the code. That's all. That's all I have. Nov 25, 2020 at 19:15
• In 12.1.1,we must set RegionBoundaryStyle -> None to remove the extra sphere, it maybe a bug. Perhaps this settings cause the kernel crash when we using DiscretizeGraphics Nov 26, 2020 at 9:05

Another way maybe use RegionPlot3D. Here we calculate the normal of surface and then perturbate the surface along the normal to create a thick surface.

r = 2 Pi;
f = Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[x];
normal = Grad[f, {x, y, z}];
norm = normal^2 // Total // Evaluate;
model = RegionPlot3D[
x^2 + y^2 + z^2 <= r^2 && f^2 <= 0.01 norm, {x, -r, r}, {y, -r,
r}, {z, -r, r}, Mesh -> None, Boxed -> False, Axes -> False,
PlotPoints -> 100]
Export["output.stl", model]
Import["output.stl"]


I tried a number of suggestions from different posts to make surface thickness work for 3D printing, but nothing worked for me until I used "Export[…,DiscretizeGraphics[model]]" as shown on this thread, and then it worked like a charm.