Skip to content

Instantly share code, notes, and snippets.

@omiq
Created July 11, 2018 01:32
Show Gist options
  • Save omiq/84e05971dc45af0add771432b280c1a3 to your computer and use it in GitHub Desktop.
Save omiq/84e05971dc45af0add771432b280c1a3 to your computer and use it in GitHub Desktop.
Load and modify an STL file and add text using Python
import os
from solid import *
from PIL import Image
def assembly(annotation=""):
a = import_stl("base.stl") + translate([5, -37, 10])(
linear_extrude(height=2, convexity=4)(
text(annotation,
size=8,
font="helvetica",
halign="center",
valign="center")))
return a
if __name__ == '__main__':
a = assembly("Hello World!")
outfile = "export.scad"
stlfile = "export.stl"
outimage = "export.png"
scad_render_to_file(a, outfile)
os.system("openscad {} -o {}".format(outfile, stlfile))
os.system("openscad --preview --imgsize=512,512 {} -o {}".format(outfile, outimage))
picture = Image.open(outimage).show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment