stl.py

changeset 14
ba3d8c56e6f5
parent 10
d26669bf424e
child 19
32de35694e56
--- a/stl.py	Wed Apr 05 00:39:31 2017 +0200
+++ b/stl.py	Wed Apr 05 00:59:45 2017 +0200
@@ -1,5 +1,9 @@
-import data, os, config, subprocess
-import vtk
+"""
+STL related helpers
+"""
+
+import os, subprocess, vtk
+import config, data
 
 OPENSCAD_MODULES = """
 module tank(x, r, h) {
@@ -29,6 +33,9 @@
 """
 
 def run_openscad(output):
+    """
+    Run openSCAD process, then convert the ascii stl to binary by using vtk
+    """
     if os.path.isfile(output):
         print "skipping existing file %s" % output
         return
@@ -47,9 +54,14 @@
     write.SetFileTypeToBinary()
     write.SetInput(reader.GetOutput())
     write.SetFileName(output)
-    write.Write() 
+    write.Write()
 
 def precompile_all_stl():
+    """
+    Write .scad temp file and
+    Invoke run_openscad for each object
+    that needs to be created in stl directory
+    """
     base = os.path.abspath('stl')
     hmin = 9999
     rmax = 0
@@ -59,7 +71,7 @@
             fn.write("tank(0, %f, %f);" % (
                 data.CYLINDER[cyl][0] / 2 * config.SCALE3D,
                 data.CYLINDER[cyl][1] * config.SCALE3D))
-        run_openscad(os.path.join(base,
+        run_openscad(os.path.join(base, \
             'cylinder_' + cyl + '.stl'))
         if data.CYLINDER[cyl][1] < hmin:
             hmin = data.CYLINDER[cyl][1]
@@ -73,6 +85,6 @@
                 pipe[1] / 2 * config.SCALE3D,
                 rmax / 2 * config.SCALE3D,
                 hmin * config.SCALE3D))
-        run_openscad(os.path.join(base,
+        run_openscad(os.path.join(base, \
             'spacer_' + pipe[0] + '.stl'))
 

mercurial