crystalscad 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/threads.rb +186 -0
- data/lib/crystalscad.rb +1 -1
- data/lib/crystalscad/Assembly.rb +1 -1
- data/lib/crystalscad/CrystalScad.rb +23 -2
- data/lib/crystalscad/Hardware.rb +13 -2
- data/lib/crystalscad/{BoltHoles.rb → ScrewThreads.rb} +40 -10
- data/lib/crystalscad/version.rb +1 -1
- metadata +6 -5
data/examples/threads.rb
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
#!/usr/bin/ruby1.9.3
|
2
|
+
require "rubygems"
|
3
|
+
require "crystalscad"
|
4
|
+
include CrystalScad
|
5
|
+
|
6
|
+
# This example shows the use of ScrewThreads in CrystalScad.
|
7
|
+
|
8
|
+
class BlackBox < CrystalScad::Assembly
|
9
|
+
# This is a box (the part that you want to make a mount for)
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@x=200
|
13
|
+
@y=100
|
14
|
+
@z=50
|
15
|
+
end
|
16
|
+
|
17
|
+
# note: when you design a box like that, make sure that it starts at 0,0,0
|
18
|
+
def show
|
19
|
+
cube([@x,@y,@z]).color(r:10,b:10,g:10,a:150)
|
20
|
+
end
|
21
|
+
|
22
|
+
# We're defining threads on every side. It must be called thread_side
|
23
|
+
# where side is either top, bottom, left, right, front, back
|
24
|
+
def threads_top
|
25
|
+
holes =*ScrewThread.new(x:50,y:50,size:8,depth:10) # note that =* creates an Array
|
26
|
+
holes << ScrewThread.new(x:150,y:50,size:8,depth:10) # and << adds stuff to an Array
|
27
|
+
end
|
28
|
+
|
29
|
+
def threads_bottom
|
30
|
+
holes =*ScrewThread.new(x:50,y:50,size:8,depth:10)
|
31
|
+
end
|
32
|
+
|
33
|
+
# note that the coordinates for the threads are needed in 2 directions from 0,0,0
|
34
|
+
# on top and bottom you're defining x & y
|
35
|
+
# on left and right you're defining y & z
|
36
|
+
# on front and back you're defining x & z
|
37
|
+
def threads_left
|
38
|
+
holes =*ScrewThread.new(y:15,z:10,size:3,depth:5)
|
39
|
+
holes << ScrewThread.new(y:40,z:30,size:3,depth:5)
|
40
|
+
end
|
41
|
+
|
42
|
+
def threads_right
|
43
|
+
holes =*ScrewThread.new(y:15,z:10,size:3,depth:5)
|
44
|
+
holes << ScrewThread.new(y:40,z:30,size:3,depth:5)
|
45
|
+
end
|
46
|
+
|
47
|
+
# this example has different thread sizes for m3 and m6
|
48
|
+
def threads_front
|
49
|
+
holes =*ScrewThread.new(x:20,z:10,size:3,depth:5)
|
50
|
+
holes << ScrewThread.new(x:100,z:20,size:6,depth:25)
|
51
|
+
holes << ScrewThread.new(x:140,z:20,size:6,depth:25)
|
52
|
+
holes << ScrewThread.new(x:180,z:45,size:3,depth:5)
|
53
|
+
end
|
54
|
+
|
55
|
+
def threads_back
|
56
|
+
holes =*ScrewThread.new(x:20,z:10,size:3,depth:5)
|
57
|
+
holes << ScrewThread.new(x:100,z:25,size:12,depth:25)
|
58
|
+
holes << ScrewThread.new(x:180,z:45,size:3,depth:5)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
# this is what a basic mount looks like.
|
64
|
+
class BlackBoxMountTop < CrystalScad::Printed
|
65
|
+
def part(show)
|
66
|
+
box = BlackBox.new
|
67
|
+
mount = cube(x:200,y:100,z:7)
|
68
|
+
# the mount should either be a cube or an object that returns x,y,z as dimensions
|
69
|
+
# if you have a complicated part, split the cube and add it later on to your object
|
70
|
+
# Alternatively, define height in the arguments.
|
71
|
+
|
72
|
+
# create_bolts needs the face as first argument, your new mount as second argument
|
73
|
+
# and the object that has the threads as third argument
|
74
|
+
# it accepts an hash of arguments as 4th argument. You can define
|
75
|
+
# height: define a custom height of your mount
|
76
|
+
# bolt_height: custom height for your bolt(s). Can also be an array for different lengths.
|
77
|
+
# This is useful if the automatic length calculation doesn't produce values
|
78
|
+
# that are available.
|
79
|
+
# This example would, without the setting 16 produce a M8x17 bolt. We don't have
|
80
|
+
# that size, so we use M8x16 instead.
|
81
|
+
|
82
|
+
bolts = create_bolts("top",mount,box,bolt_height:16)
|
83
|
+
mount-=bolts
|
84
|
+
mount+=bolts if show
|
85
|
+
|
86
|
+
res = mount.translate(z:box.z)
|
87
|
+
res += box.show if show
|
88
|
+
res
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class BlackBoxMountBottom < CrystalScad::Printed
|
93
|
+
def part(show)
|
94
|
+
box = BlackBox.new
|
95
|
+
mount = cube(x:200,y:100,z:z=2)
|
96
|
+
# note that the bolt height bom output is unchecked in this and the following examples
|
97
|
+
bolts = create_bolts("bottom",mount,box)
|
98
|
+
mount-=bolts
|
99
|
+
mount+=bolts if show
|
100
|
+
|
101
|
+
res = mount.translate(z:-z)
|
102
|
+
res += box.show if show
|
103
|
+
res
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class BlackBoxMountLeft < CrystalScad::Printed
|
108
|
+
def part(show)
|
109
|
+
box = BlackBox.new
|
110
|
+
mount = cube(x:x=5,y:100,z:50)
|
111
|
+
|
112
|
+
|
113
|
+
bolts = create_bolts("left",mount,box)
|
114
|
+
mount-=bolts
|
115
|
+
mount+=bolts if show
|
116
|
+
|
117
|
+
res = mount.translate(x:-x)
|
118
|
+
res += box.show if show
|
119
|
+
res
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class BlackBoxMountRight < CrystalScad::Printed
|
124
|
+
def part(show)
|
125
|
+
box = BlackBox.new
|
126
|
+
mount = cube(x:5,y:100,z:50)
|
127
|
+
|
128
|
+
bolts = create_bolts("right",mount,box)
|
129
|
+
mount-=bolts
|
130
|
+
mount+=bolts if show
|
131
|
+
|
132
|
+
res = mount.translate(x:box.x)
|
133
|
+
res += box.show if show
|
134
|
+
res
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class BlackBoxMountFront < CrystalScad::Printed
|
139
|
+
def part(show)
|
140
|
+
box = BlackBox.new
|
141
|
+
mount = cube(x:box.x,y:y=15,z:box.z)
|
142
|
+
|
143
|
+
bolts = create_bolts("front",mount,box)
|
144
|
+
mount-=bolts
|
145
|
+
mount+=bolts if show
|
146
|
+
|
147
|
+
res = mount.translate(y:-y)
|
148
|
+
res += box.show if show
|
149
|
+
res
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
class BlackBoxMountBack < CrystalScad::Printed
|
154
|
+
def part(show)
|
155
|
+
box = BlackBox.new
|
156
|
+
mount = cube(x:box.x,y:35,z:box.z)
|
157
|
+
|
158
|
+
bolts = create_bolts("back",mount,box)
|
159
|
+
mount-=bolts
|
160
|
+
mount+=bolts if show
|
161
|
+
|
162
|
+
res = mount.translate(y:box.y)
|
163
|
+
res += box.show if show
|
164
|
+
res
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
b=CrystalScadObject.new
|
170
|
+
|
171
|
+
# uncomment as many mounts as you like here
|
172
|
+
|
173
|
+
b +=BlackBoxMountTop.new.show
|
174
|
+
#b +=BlackBoxMountBottom.new.show
|
175
|
+
#b +=BlackBoxMountLeft.new.show
|
176
|
+
#b +=BlackBoxMountRight.new.show
|
177
|
+
#b +=BlackBoxMountFront.new.show
|
178
|
+
#b +=BlackBoxMountBack.new.show
|
179
|
+
|
180
|
+
# you can also try output instead of show
|
181
|
+
#b =BlackBoxMountTop.new.output
|
182
|
+
|
183
|
+
# Uncomment this for checking the BOM output
|
184
|
+
# puts @@bom.output
|
185
|
+
|
186
|
+
b.save("threads.scad")
|
data/lib/crystalscad.rb
CHANGED
data/lib/crystalscad/Assembly.rb
CHANGED
@@ -21,7 +21,7 @@ module CrystalScad
|
|
21
21
|
include CrystalScad::Hardware
|
22
22
|
include CrystalScad::LinearBearing
|
23
23
|
include CrystalScad::Gears
|
24
|
-
include CrystalScad::
|
24
|
+
include CrystalScad::ScrewThreads
|
25
25
|
|
26
26
|
|
27
27
|
class CrystalScadObject
|
@@ -178,6 +178,13 @@ module CrystalScad
|
|
178
178
|
end
|
179
179
|
|
180
180
|
def square(args)
|
181
|
+
if args.kind_of? Array
|
182
|
+
args = {size:args}
|
183
|
+
elsif args.kind_of? Hash
|
184
|
+
args[:x] ||= 0
|
185
|
+
args[:y] ||= 0
|
186
|
+
args = {size:[args[:x],args[:y]]}
|
187
|
+
end
|
181
188
|
Square.new(args)
|
182
189
|
end
|
183
190
|
|
@@ -351,7 +358,13 @@ module CrystalScad
|
|
351
358
|
if attributes.kind_of? String
|
352
359
|
attributes = "\"#{attributes}\""
|
353
360
|
elsif attributes.kind_of? Hash
|
354
|
-
|
361
|
+
attributes[:a] ||= 255
|
362
|
+
|
363
|
+
r = attributes[:r].to_f / 255.0
|
364
|
+
g = attributes[:g].to_f / 255.0
|
365
|
+
b = attributes[:b].to_f / 255.0
|
366
|
+
a = attributes[:a].to_f / 255.0
|
367
|
+
attributes = [r,g,b,a]
|
355
368
|
end
|
356
369
|
|
357
370
|
super(object, attributes)
|
@@ -385,11 +398,19 @@ module CrystalScad
|
|
385
398
|
end
|
386
399
|
|
387
400
|
def linear_extrude(args)
|
401
|
+
if args[:h] # rename to height
|
402
|
+
args[:height] = args[:h]
|
403
|
+
args.delete(:h)
|
404
|
+
end
|
388
405
|
args = args.collect { |k, v| "#{k} = #{v}" }.join(', ')
|
389
406
|
return LinearExtrude.new(self,args)
|
390
407
|
end
|
391
408
|
|
392
409
|
def rotate_extrude(args)
|
410
|
+
if args[:h] # rename to height
|
411
|
+
args[:height] = args[:h]
|
412
|
+
args.delete(:h)
|
413
|
+
end
|
393
414
|
args = args.collect { |k, v| "#{k} = #{v}" }.join(', ')
|
394
415
|
return RotateExtrude.new(self,args)
|
395
416
|
end
|
data/lib/crystalscad/Hardware.rb
CHANGED
@@ -128,13 +128,24 @@ module CrystalScad::Hardware
|
|
128
128
|
@args[:type] ||= "125"
|
129
129
|
@args[:material] ||= "steel"
|
130
130
|
@args[:surface] ||= "zinc plated"
|
131
|
-
|
131
|
+
|
132
132
|
@chart_din125 = { 3.2 => {outer_diameter:7, height:0.5},
|
133
|
-
|
133
|
+
3.7 => {outer_diameter:8, height:0.5},
|
134
|
+
4.3 => {outer_diameter:9, height:0.8},
|
134
135
|
5.3 => {outer_diameter:10, height:1.0},
|
136
|
+
6.4 => {outer_diameter:12, height:1.6},
|
137
|
+
8.4 => {outer_diameter:16, height:1.6},
|
138
|
+
10.5 => {outer_diameter:20, height:2.0},
|
139
|
+
13.0 => {outer_diameter:24, height:2.5},
|
135
140
|
|
136
141
|
}
|
142
|
+
if @chart_din125[@size] == nil
|
143
|
+
sizes = @chart_din125.map{|k,v| k}.sort.reverse.map{|s| s > @size ? size=s :nil}
|
144
|
+
@size = size
|
145
|
+
end
|
137
146
|
@height = @chart_din125[@size][:height]
|
147
|
+
|
148
|
+
|
138
149
|
end
|
139
150
|
|
140
151
|
def description
|
@@ -13,8 +13,8 @@
|
|
13
13
|
# You should have received a copy of the GNU General Public License
|
14
14
|
# along with CrystalScad. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
|
-
module CrystalScad::
|
17
|
-
class
|
16
|
+
module CrystalScad::ScrewThreads
|
17
|
+
class ScrewThread
|
18
18
|
# I would name this Thread but that's already taken by something else
|
19
19
|
|
20
20
|
attr_accessor :x,:y,:z,:size, :depth
|
@@ -39,23 +39,37 @@ module CrystalScad::BoltHoles
|
|
39
39
|
|
40
40
|
# we need to know obj1 height (if not supplied by user)
|
41
41
|
height ||= args[:height]
|
42
|
-
|
42
|
+
case face
|
43
|
+
when "top"
|
44
|
+
height ||= obj1.z rescue nil
|
45
|
+
when "bottom"
|
46
|
+
height ||= obj1.z rescue nil
|
47
|
+
when "left"
|
48
|
+
height ||= obj1.x rescue nil
|
49
|
+
when "right"
|
50
|
+
height ||= obj1.x rescue nil
|
51
|
+
when "front"
|
52
|
+
height ||= obj1.y rescue nil
|
53
|
+
when "back"
|
54
|
+
height ||= obj1.y rescue nil
|
55
|
+
end
|
43
56
|
height ||= obj1.height rescue nil
|
44
57
|
if height == nil
|
45
58
|
raise "the object we're substracting from doesn't have a height defined; please define manually"
|
46
59
|
return
|
47
60
|
end
|
48
61
|
|
49
|
-
# lets check if the obj2 responds to the
|
62
|
+
# lets check if the obj2 responds to the threads_[face] method
|
50
63
|
|
51
|
-
meth = "
|
64
|
+
meth = "threads_#{face}"
|
52
65
|
|
53
66
|
unless obj2.respond_to?(meth)
|
54
|
-
raise "The object you're trying to get bolts
|
67
|
+
raise "The object you're trying to get bolts from doesn't supply any on the face '#{face}'. Please add a method #{meth} to this object"
|
55
68
|
return
|
56
69
|
end
|
57
70
|
holes = obj2.send(meth)
|
58
71
|
|
72
|
+
return if holes == nil
|
59
73
|
|
60
74
|
# let the user either define bolt_heights as integer, array or none (will be guessed)
|
61
75
|
if args[:bolt_height].kind_of? Array
|
@@ -78,10 +92,26 @@ module CrystalScad::BoltHoles
|
|
78
92
|
ret = []
|
79
93
|
holes.each_with_index do |hole,i|
|
80
94
|
bolt = Bolt.new(hole.size,bolt_heights[i])
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
95
|
+
puts bolt_heights[i]
|
96
|
+
case face
|
97
|
+
when "top"
|
98
|
+
bolt.transformations << Rotate.new(x:180)
|
99
|
+
bolt.transformations << Translate.new({x:hole.x,y:hole.y,z:hole.z+height})
|
100
|
+
when "bottom"
|
101
|
+
bolt.transformations << Translate.new({x:hole.x,y:hole.y,z:hole.z})
|
102
|
+
when "left"
|
103
|
+
bolt.transformations << Rotate.new(y:90)
|
104
|
+
bolt.transformations << Translate.new({x:hole.x,y:hole.y,z:hole.z+height})
|
105
|
+
when "right"
|
106
|
+
bolt.transformations << Rotate.new(y:-90)
|
107
|
+
bolt.transformations << Translate.new({x:hole.x+height,y:hole.y,z:hole.z})
|
108
|
+
when "front"
|
109
|
+
bolt.transformations << Rotate.new(x:-90)
|
110
|
+
bolt.transformations << Translate.new({x:hole.x,y:hole.y,z:hole.z})
|
111
|
+
when "back"
|
112
|
+
bolt.transformations << Rotate.new(x:90)
|
113
|
+
bolt.transformations << Translate.new({x:hole.x,y:hole.y+height,z:hole.z})
|
114
|
+
end
|
85
115
|
|
86
116
|
ret << bolt
|
87
117
|
end
|
data/lib/crystalscad/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crystalscad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 7
|
10
|
+
version: 0.3.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joachim Glauche
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-12-
|
18
|
+
date: 2013-12-29 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rubyscad
|
@@ -64,14 +64,15 @@ files:
|
|
64
64
|
- crystalscad.gemspec
|
65
65
|
- examples/gear.rb
|
66
66
|
- examples/stack.rb
|
67
|
+
- examples/threads.rb
|
67
68
|
- lib/crystalscad.rb
|
68
69
|
- lib/crystalscad/Assembly.rb
|
69
70
|
- lib/crystalscad/BillOfMaterial.rb
|
70
|
-
- lib/crystalscad/BoltHoles.rb
|
71
71
|
- lib/crystalscad/CrystalScad.rb
|
72
72
|
- lib/crystalscad/Gears.rb
|
73
73
|
- lib/crystalscad/Hardware.rb
|
74
74
|
- lib/crystalscad/LinearBearing.rb
|
75
|
+
- lib/crystalscad/ScrewThreads.rb
|
75
76
|
- lib/crystalscad/version.rb
|
76
77
|
- skeleton_project/assemblies/example.rb
|
77
78
|
- skeleton_project/observe.sh
|