cylindertransport.py

changeset 6
57f17c62c137
parent 5
c2158ae1dc05
child 8
63b6f80e09ef
--- a/cylindertransport.py	Mon Apr 03 04:47:41 2017 +0200
+++ b/cylindertransport.py	Mon Apr 03 05:21:17 2017 +0200
@@ -26,8 +26,7 @@
         self.cylinders = cylinders
         self.space_min = space_min
         self.font = FONTBASE + "arial.ttf"
-        self.scad = "// Color support only in compile mode (F5)\n" +\
-            "include <cylindertransport.scad>\n"
+        self.scad = "// Color support only in compile mode (F5)\n"
         self.circles = []
         self.spacings = []
         self.margin = 20
@@ -150,6 +149,9 @@
     parser.add_argument('--space', dest='space_min', \
         type=int, default=10, \
         help='minimum space between cylinders (mm)')
+    parser.add_argument('--scad', dest='scad', \
+        type=str, default="", metavar='filename', \
+        help='Write OpenSCAD script file')
 
     options = parser.parse_args()
 
@@ -164,9 +166,36 @@
     img = worker.render_image()
     img.show()
 
-    print "\n// ------------ START SCAD SCRIPT ------------"
-    print worker.scad + "// ------------ END SCAD SCRIPT ------------"
+    if (options.scad != ""):
+        with open(options.scad, "w") as fd:
+            fd.write("""// cylindertransport.py OpenSCAD script
+module tank(x, r, h) {
+    cap = r;
+    color("SteelBlue") render() rotate([90,0,0]) {
+    translate([x, r, cap]) {
+        sphere(r = r); // bottom
+        cylinder(h = h-2*cap, r = r);
+    }
+    translate([x, r, h-cap]) {
+        sphere(r = r); // top
+        cylinder(h = 30+cap, r = 25);
+    }
+    }
+}
 
+module spacer(x, r, rcylinder, h) {
+    cap = rcylinder;
+
+    color("DarkGrey") render() rotate([90,0,0])
+    translate([x, r, cap]) {
+        difference() {
+            cylinder(h = h-2*cap, r = r);
+            cylinder(h = h-2*cap, r = r-5);
+        }
+    }
+}
+$fn = 20;\n""")
+            fd.write(worker.scad)
 
 if __name__ == "__main__":
     run()

mercurial