|
1 | 1 | #! /usr/bin/env python |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 |
|
4 | | -# Basic shape with several repeated parts, demonstrating the use of |
5 | | -# solid.utils.bill_of_materials() |
| 4 | +# Basic shape with several repeated parts, demonstrating the use of |
| 5 | +# solid.utils.bill_of_materials() |
6 | 6 | # |
7 | | -# Basically: |
| 7 | +# Basically: |
8 | 8 | # -- Define every part you want in the Bill of Materials in a function |
9 | 9 | # -- Use the 'bom_part' decorator ahead of the definition of each part's function |
10 | | -# e.g.: |
11 | | - # @bom_part() |
12 | | - # def my_part(): |
13 | | - # pass |
14 | | -# -- Optionally, you can add a description and a per-unit cost to the |
15 | | -# decorator invocations. |
| 10 | +# e.g.: |
| 11 | +# @bom_part() |
| 12 | +# def my_part(): |
| 13 | +# pass |
| 14 | +# -- Optionally, you can add a description and a per-unit cost to the |
| 15 | +# decorator invocations. |
16 | 16 | # |
17 | 17 | # -- To generate the bill of materials, call solid.utils.bill_of_materials() |
18 | 18 | # |
19 | 19 | # -ETJ 08 Mar 2011 |
20 | 20 |
|
21 | | -import os, sys |
| 21 | +import os |
| 22 | +import sys |
22 | 23 |
|
23 | 24 | from solid import * |
24 | 25 | from solid.utils import * |
|
33 | 34 |
|
34 | 35 | doohickey_h = 5 |
35 | 36 |
|
| 37 | + |
36 | 38 | def head(): |
37 | | - return cylinder(h=head_height, r =head_rad) |
| 39 | + return cylinder(h=head_height, r=head_rad) |
38 | 40 |
|
39 | 41 |
|
40 | 42 | @bom_part("M3x16 Bolt", 0.12, currency="€") |
41 | 43 | def m3_16(a=3): |
42 | 44 | bolt_height = 16 |
43 | 45 | m = union()( |
44 | | - head(), |
45 | | - translate( [0,0, -bolt_height])( |
46 | | - cylinder(r=m3_rad, h=bolt_height) |
47 | | - ) |
| 46 | + head(), |
| 47 | + translate([0, 0, -bolt_height])( |
| 48 | + cylinder(r=m3_rad, h=bolt_height) |
48 | 49 | ) |
| 50 | + ) |
49 | 51 | return m |
50 | 52 |
|
51 | 53 |
|
52 | 54 | @bom_part("M3x12 Bolt", 0.09) |
53 | 55 | def m3_12(): |
54 | 56 | bolt_height = 12 |
55 | 57 | m = union()( |
56 | | - head(), |
57 | | - translate( [ 0, 0, -bolt_height])( |
58 | | - cylinder(r=m3_rad, h=bolt_height) |
59 | | - ) |
| 58 | + head(), |
| 59 | + translate([0, 0, -bolt_height])( |
| 60 | + cylinder(r=m3_rad, h=bolt_height) |
60 | 61 | ) |
| 62 | + ) |
61 | 63 | return m |
62 | 64 |
|
63 | 65 |
|
64 | 66 | @bom_part("M3 Nut", 0.04, currency="R$") |
65 | 67 | def m3_nut(): |
66 | 68 | hx = cylinder(r=nut_rad, h=nut_height) |
67 | | - hx.add_param('$fn', 6) # make the nut hexagonal |
| 69 | + hx.add_param('$fn', 6) # make the nut hexagonal |
68 | 70 | n = difference()( |
69 | | - hx, |
70 | | - translate([0,0,-EPSILON])( |
71 | | - cylinder(r=m3_rad, h=nut_height+2*EPSILON ) |
72 | | - ) |
| 71 | + hx, |
| 72 | + translate([0, 0, -EPSILON])( |
| 73 | + cylinder(r=m3_rad, h=nut_height + 2 * EPSILON) |
73 | 74 | ) |
| 75 | + ) |
74 | 76 | return n |
75 | 77 |
|
76 | 78 |
|
77 | 79 | @bom_part() |
78 | 80 | def doohickey(): |
79 | | - hole_cyl = translate([0,0,-EPSILON])( |
80 | | - cylinder(r=m3_rad, h=doohickey_h+2*EPSILON ) |
81 | | - ) |
| 81 | + hole_cyl = translate([0, 0, -EPSILON])( |
| 82 | + cylinder(r=m3_rad, h=doohickey_h + 2 * EPSILON) |
| 83 | + ) |
82 | 84 | d = difference()( |
83 | | - cube([30, 10, doohickey_h], center=True), |
84 | | - translate([-10, 0,0])(hole_cyl), |
85 | | - hole_cyl, |
86 | | - translate([10,0,0])(hole_cyl) |
87 | | - ) |
| 85 | + cube([30, 10, doohickey_h], center=True), |
| 86 | + translate([-10, 0, 0])(hole_cyl), |
| 87 | + hole_cyl, |
| 88 | + translate([10, 0, 0])(hole_cyl) |
| 89 | + ) |
88 | 90 | return d |
89 | 91 |
|
90 | 92 |
|
91 | 93 | def assemble(): |
92 | 94 | return union()( |
93 | | - doohickey(), |
94 | | - translate( [-10, 0, doohickey_h/2])( m3_12()), |
95 | | - translate( [ 0, 0, doohickey_h/2])( m3_16()), |
96 | | - translate( [10, 0, doohickey_h/2])( m3_12()), |
97 | | - # Nuts |
98 | | - translate( [-10, 0, -nut_height-doohickey_h/2])( m3_nut()), |
99 | | - translate( [ 0, 0, -nut_height-doohickey_h/2])( m3_nut()), |
100 | | - translate( [10, 0, -nut_height-doohickey_h/2])( m3_nut()), |
101 | | - ) |
102 | | - |
103 | | -if __name__ == '__main__': |
| 95 | + doohickey(), |
| 96 | + translate([-10, 0, doohickey_h / 2])(m3_12()), |
| 97 | + translate([ 0, 0, doohickey_h / 2])(m3_16()), |
| 98 | + translate([ 10, 0, doohickey_h / 2])(m3_12()), |
| 99 | + # Nuts |
| 100 | + translate([-10, 0, -nut_height - doohickey_h / 2])(m3_nut()), |
| 101 | + translate([ 0, 0, -nut_height - doohickey_h / 2])(m3_nut()), |
| 102 | + translate([ 10, 0, -nut_height - doohickey_h / 2])(m3_nut()), |
| 103 | + ) |
| 104 | + |
| 105 | +if __name__ == '__main__': |
104 | 106 | out_dir = sys.argv[1] if len(sys.argv) > 1 else os.curdir |
105 | 107 | file_out = os.path.join(out_dir, 'BOM_example.scad') |
106 | | - |
| 108 | + |
107 | 109 | a = assemble() |
108 | | - |
| 110 | + |
109 | 111 | bom = bill_of_materials() |
110 | | - |
111 | | - print("%(__file__)s: SCAD file written to: \n%(file_out)s"%vars()) |
| 112 | + |
| 113 | + print("%(__file__)s: SCAD file written to: \n%(file_out)s" % vars()) |
112 | 114 | print(bom) |
113 | | - |
| 115 | + |
114 | 116 | scad_render_to_file(a, file_out) |
0 commit comments