1
Fork 0
internship/olaflow/processing/stl.py
2022-03-28 10:27:38 +02:00

23 lines
704 B
Python

import pathlib
import shutil
import subprocess
import tempfile
import numpy as np
def stl_from_1d(data, output, scale=[1, 1, 1], translate=[0, 0, 0]):
with tempfile.TemporaryDirectory() as tmppath:
tmpdir = pathlib.Path(tmppath)
np.savetxt(tmpdir.joinpath("data.dat"), np.stack((data, data)))
with open(tmpdir.joinpath("scad"), "wt") as scad:
scad.write(
f"mirror([1, 0, 0])"
f"translate({translate})"
f"scale({scale})"
f"""surface("data.dat");"""
)
subprocess.run(("openscad", "scad", "-o", "data.stl"), cwd=tmpdir)
shutil.copy2(tmpdir.joinpath("data.stl"), output)