cylindertransport.py

changeset 6
57f17c62c137
parent 5
c2158ae1dc05
child 8
63b6f80e09ef
equal deleted inserted replaced
5:c2158ae1dc05 6:57f17c62c137
24 """ 24 """
25 def __init__(self, cylinders, space_min=10): 25 def __init__(self, cylinders, space_min=10):
26 self.cylinders = cylinders 26 self.cylinders = cylinders
27 self.space_min = space_min 27 self.space_min = space_min
28 self.font = FONTBASE + "arial.ttf" 28 self.font = FONTBASE + "arial.ttf"
29 self.scad = "// Color support only in compile mode (F5)\n" +\ 29 self.scad = "// Color support only in compile mode (F5)\n"
30 "include <cylindertransport.scad>\n"
31 self.circles = [] 30 self.circles = []
32 self.spacings = [] 31 self.spacings = []
33 self.margin = 20 32 self.margin = 20
34 33
35 def calc_min(self, r_1, r_2): 34 def calc_min(self, r_1, r_2):
148 parser.add_argument('cylinders', metavar='cylinder', \ 147 parser.add_argument('cylinders', metavar='cylinder', \
149 type=str, nargs='+', help='cylinder types') 148 type=str, nargs='+', help='cylinder types')
150 parser.add_argument('--space', dest='space_min', \ 149 parser.add_argument('--space', dest='space_min', \
151 type=int, default=10, \ 150 type=int, default=10, \
152 help='minimum space between cylinders (mm)') 151 help='minimum space between cylinders (mm)')
152 parser.add_argument('--scad', dest='scad', \
153 type=str, default="", metavar='filename', \
154 help='Write OpenSCAD script file')
153 155
154 options = parser.parse_args() 156 options = parser.parse_args()
155 157
156 for test in options.cylinders: 158 for test in options.cylinders:
157 if not test in CYLINDER.keys(): 159 if not test in CYLINDER.keys():
162 options.cylinders, options.space_min) 164 options.cylinders, options.space_min)
163 165
164 img = worker.render_image() 166 img = worker.render_image()
165 img.show() 167 img.show()
166 168
167 print "\n// ------------ START SCAD SCRIPT ------------" 169 if (options.scad != ""):
168 print worker.scad + "// ------------ END SCAD SCRIPT ------------" 170 with open(options.scad, "w") as fd:
169 171 fd.write("""// cylindertransport.py OpenSCAD script
172 module tank(x, r, h) {
173 cap = r;
174 color("SteelBlue") render() rotate([90,0,0]) {
175 translate([x, r, cap]) {
176 sphere(r = r); // bottom
177 cylinder(h = h-2*cap, r = r);
178 }
179 translate([x, r, h-cap]) {
180 sphere(r = r); // top
181 cylinder(h = 30+cap, r = 25);
182 }
183 }
184 }
185
186 module spacer(x, r, rcylinder, h) {
187 cap = rcylinder;
188
189 color("DarkGrey") render() rotate([90,0,0])
190 translate([x, r, cap]) {
191 difference() {
192 cylinder(h = h-2*cap, r = r);
193 cylinder(h = h-2*cap, r = r-5);
194 }
195 }
196 }
197 $fn = 20;\n""")
198 fd.write(worker.scad)
170 199
171 if __name__ == "__main__": 200 if __name__ == "__main__":
172 run() 201 run()

mercurial