Class: SolidRuby::Assemblies::Nut
Instance Attribute Summary collapse
Attributes inherited from Assembly
#hardware, #skip, #transformations, #x, #y, #z
#attributes, #children, #siblings, #transformations
Instance Method Summary
collapse
Methods inherited from Assembly
#*, #+, #-, #add_to_bom, #color, #colorize, get_skip, get_views, #part, #scad_output, #show_hardware, skip, #threads, #transform, view, #walk_tree
#&, alias_attr, #debug, #debug?, #mirror, #place, #rotate, #rotate_around, #save, #scale, #to_rubyscad, #translate, #union, #walk_tree, #walk_tree_classes
Constructor Details
#initialize(size, args = {}) ⇒ Nut
Returns a new instance of Nut.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/solidruby/assemblies/nut.rb', line 19
def initialize(size, args = {})
@size = size
@type = args[:type] ||= '934'
@material = args[:material] ||= '8.8'
@surface = args[:surface] ||= 'zinc plated'
@support = args[:support] ||= false
@support_layer_height = args[:support_layer_height] ||= 0.2
@margin = args[:margin] ||= 0.3
@slot = args[:slot] || nil
@slot_margin = args[:slot_margin] || 0.5
@slot_direction = args[:slot_direction] || 'z'
@cylinder_length = args[:cylinder_length] || 0
@transformations ||= []
@args = args
prepare_data
@height = args[:height] || @height
@direction = args[:direction] || @slot_direction
@bolt = nil
super(args)
end
|
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
18
19
20
|
# File 'lib/solidruby/assemblies/nut.rb', line 18
def height
@height
end
|
Instance Method Details
#add_support(layer_height = @support_layer_height) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/solidruby/assemblies/nut.rb', line 98
def add_support(layer_height = @support_layer_height)
res = cylinder(d: @support_diameter, h: @height - layer_height)
res += cylinder(d:@s-1,h:layer_height) if @size < 6
res
end
|
#bolt(length = nil, args = {}) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/solidruby/assemblies/nut.rb', line 48
def bolt(length = nil, args = {})
return @bolt if @bolt
@bolt = Bolt.new(@size, length, args)
case @direction
when 'z'
bolt.transformations << Rotate.new(x: 180)
bolt.transformations << Translate.new(z: length)
when '-z'
bolt.transformations << Translate.new(z: -length + @height)
when '-x'
bolt.transformations << Rotate.new(x: 180)
bolt.transformations << Translate.new(z: length)
when 'x'
bolt.transformations << Translate.new(z: -length + @height)
when '-y'
bolt.transformations << Rotate.new(x: 180)
bolt.transformations << Translate.new(z: length)
when 'y'
bolt.transformations << Translate.new(z: -length + @height)
end
@bolt.transformations += transformations.dup
@bolt
end
|
#description ⇒ Object
44
45
46
|
# File 'lib/solidruby/assemblies/nut.rb', line 44
def description
"M#{@size} Nut, DIN #{@type}, #{@material} #{@surface}"
end
|
#nut_934(show = true, margin = 0, height_margin = 0) ⇒ Object
144
145
146
147
148
149
150
151
|
# File 'lib/solidruby/assemblies/nut.rb', line 144
def nut_934(show = true, margin = 0, height_margin = 0)
@s += margin
res = cylinder(d: (@s / Math.sqrt(3)) * 2, h: @height + height_margin, fn: 6)
res -= cylinder(d: @size, h: @height) if show == true
res -= add_support if @support
res.color('Gainsboro')
end
|
#output ⇒ Object
130
131
132
133
134
135
136
137
|
# File 'lib/solidruby/assemblies/nut.rb', line 130
def output
add_to_bom
if @slot.nil?
return transform(nut_934(false, @margin))
else
return transform(slot)
end
end
|
#prepare_data ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/solidruby/assemblies/nut.rb', line 73
def prepare_data
chart_934 = {
2.5 => { side_to_side: 5, height: 2, support_diameter: 2.8 },
3 => { side_to_side: 5.5, height: 2.4, support_diameter: 3.5 },
4 => { side_to_side: 7, height: 3.2, support_diameter: 4.4 },
5 => { side_to_side: 8, height: 4, support_diameter: 5.3 },
6 => { side_to_side: 10, height: 5, support_diameter: 6.3 },
8 => { side_to_side: 13, height: 6.5, support_diameter: 8.3 },
10 => { side_to_side: 17, height: 8, support_diameter: 10.3 },
12 => { side_to_side: 19, height: 10, support_diameter: 12.3 }
}
chart_985 = {
3 => { height: 4 },
4 => { height: 5 },
5 => { height: 5 },
6 => { height: 6 }
}
@s = chart_934[@size][:side_to_side]
@height = chart_934[@size][:height]
@support_diameter = chart_934[@size][:support_diameter]
@height = chart_985[@size][:height] if @type == "985"
end
|
#show ⇒ Object
139
140
141
142
|
# File 'lib/solidruby/assemblies/nut.rb', line 139
def show
add_to_bom
transform(nut_934)
end
|
#slot ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/solidruby/assemblies/nut.rb', line 105
def slot
case @slot_direction
when 'x'
pos = { x: @slot }
when 'y'
pos = { y: @slot }
when 'z'
pos = { z: @slot }
when '-x'
pos = { x: -@slot }
when '-y'
pos = { y: -@slot }
when '-z'
pos = { z: -@slot }
else
raise "Invalid slot direction #{@slot_direction}"
end
res = hull(
nut_934(false, @margin, @slot_margin),
nut_934(false, @margin, @slot_margin).translate(pos)
)
res += cylinder(d:@size+@margin,h:@cylinder_length) if @cylinder_length > 0
res
end
|