finishing cylindertransport_v1

Mon, 03 Apr 2017 05:21:17 +0200

author
mdd
date
Mon, 03 Apr 2017 05:21:17 +0200
changeset 6
57f17c62c137
parent 5
c2158ae1dc05
child 7
9b6867df00c9

finishing

cylindertransport.py file | annotate | diff | comparison | revisions
cylindertransport.scad file | annotate | diff | comparison | revisions
cylindertransport.sh file | annotate | diff | comparison | revisions
--- 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()
--- a/cylindertransport.scad	Mon Apr 03 04:47:41 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*
-	OpenSCAD Template for visualizing cylindertransport.py
-*/
-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;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cylindertransport.sh	Mon Apr 03 05:21:17 2017 +0200
@@ -0,0 +1,6 @@
+#!/bin/bash
+python cylindertransport.py --scad /tmp/cylinders.scad "$@"
+if [ $? -ne 0 ]; then
+    exit $?
+fi
+openscad /tmp/cylinders.scad &

mercurial