forked from URJCMakerGroup/MakerWorkbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
partgroup.py
284 lines (236 loc) · 9.64 KB
/
partgroup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# ----------------------------------------------------------------------------
# -- Groups of parts, components and objects
# -- comps library
# -- Python FreeCAD functions and classes that groups components
# ----------------------------------------------------------------------------
# -- (c) Felipe Machado
# -- Area of Electronics. Rey Juan Carlos University (urjc.es)
# -- October-2016
# ----------------------------------------------------------------------------
# --- LGPL Licence
# ----------------------------------------------------------------------------
import FreeCAD;
import Part;
import Draft;
import DraftVecUtils
import logging
# ---------------------- can be taken away after debugging
import os
# directory this file is
filepath = os.getcwd()
import sys
# to get the components
# In FreeCAD can be added: Preferences->General->Macro->Macro path
sys.path.append(filepath)
# ---------------------- can be taken away after debugging
import kcomp # before, it was called mat_cte
import fcfun
import comps
from fcfun import V0, VX, VY, VZ, V0ROT, addBox, addCyl, addCyl_pos, fillet_len
from fcfun import addBolt, addBoltNut_hole, NutHole
logging.basicConfig(level=logging.DEBUG,
format='%(%(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# ----------- class BearWashGroup ----------------------------------------
class BearWashGroup(object):
"""
creates a group of bearings and washers to make idle pulleys
Receives a list of names
----- Arguments:
holcyl_list: list of objects kcomp.HollowCyl, that have the list of
objects that will be on this group. The ordering will be
from bottom to top
fc_axis_h: FreeCAD.Vector on the direction of the cylinder.
The sign matters
pos: FreeCAD.Vector that defines the position of the center of the
cylinder base
name: string with the name
----- Attributes:
holcyl_list:
normal: The normalized normal
pos: The position (argument)
height: The total height of all the components
count: The number of components
fco_list: A list with all the freecad objects
d_maxwash: The largest diameter of all the washers
d_maxbear: The largest diameter of all the bearing
r_maxwash: The largest radius of all the washers
r_maxbear: The largest radius of all the bearing
fco : cad object of the compound
"""
def __init__(self, holcyl_list,
name="bearwashgr",
normal=VZ, pos=V0):
doc = FreeCAD.ActiveDocument
self.holcyl_list = holcyl_list
self.name = name
group_h = 0 # the accumulated height
# in case the length is not 1
norm_normal = DraftVecUtils.scaleTo(normal, 1)
self.normal = norm_normal
elem_pos = pos
d_maxwash = 0
d_maxbear = 0
fco_list = [] # list of the freecad objects
for ind, elem in enumerate(holcyl_list):
fco = fcfun.addCylHolePos(r_out=elem.r_out,
r_in=elem.r_in,
h=elem.thick,
name=name + str(ind + 1),
normal=norm_normal,
pos=elem_pos)
fco_list.append(fco)
# adding the height on the same direction
elem_pos += DraftVecUtils.scale(norm_normal, elem.thick)
# print 'index: ' + str(ind) +' thick: ' +
# str(elem.thick) + ' elem_pos: ' + str(elem_pos)
group_h += elem.thick
if elem.part == 'washer':
if d_maxwash < elem.d_out:
d_maxwash = elem.d_out
elif elem.part == 'bearing':
if d_maxbear < elem.d_out:
d_maxbear = elem.d_out
self.height = group_h
self.fco_list = fco_list
self.d_maxwash = d_maxwash
self.d_maxbear = d_maxbear
self.r_maxwash = d_maxwash / 2.
self.r_maxbear = d_maxbear / 2.
self.count = len(fco_list)
self.h_pulleybelt = self.get_pulleybelt_h
bearwashgroup = doc.addObject("Part::Compound", name)
bearwashgroup.Links = fco_list
self.fco = bearwashgroup
doc.recompute()
def getmaxwashthick(holcyl_list):
"""
From a group of bearings and washers to make idle pulleys, obtains
the diameter of the larger washer
"""
maxwashthick = 0
for elem in self.holcyl_list:
if elem.part == 'washer':
if maxwashthick < elem.thick:
maxwashthick = elem.thick
return maxwashthick
def get_pulleybelt_h(self):
"""
From a list of bearings and washers to make idle pulleys, obtains
the height of the pulley for the belt, which is the height of the
bearing plus the height of the 2 regular washers:
.......
..........:.....:........ bolt head
: Holder for the pulley group
....._________________...:
|_________________|.......large washer..........
|_________| regular washer :
| | bearing + pulleybelt_h
|_________| :
___|_________|___........regular washer.......:
....|_________________|.. large washer
:
.........................: Holder for the pulley group
:.....: nut
:.: bolt shank
Return:
-------
The height of the part of objects for the belt
"""
pulleybelt_h = 0
for (ind, elem) in enumerate(self.holcyl_list):
if elem.part == 'bearing':
pulleybelt_h += elem.thick
pulleybelt_h += prev_elem.thick # the previous washer
break
prev_elem = elem
ind += 1 # the next element to the bearing: the washer
pulleybelt_h += self.holcyl_list[ind].thick
return pulleybelt_h
# ----------- end class BearWashGroup ----------------------------------------
# From a group of bearings and washers to make idle pulleys, obtains
# the diameter of the larger washer
def getmaxwashdiam(holcyl_list):
maxwashdiam = 0
for elem in holcyl_list:
if elem.part == 'washer':
if maxwashdiam < elem.d_out:
maxwashdiam = elem.d_out
return maxwashdiam
# From a group of bearings and washers to make idle pulleys, obtains
# the diameter of the larger bearing
# check that it is the same as get_idlepull_maxbear_d in kcomp.py
def getmaxbeardiam(holcyl_list):
maxbeardiam = 0
for elem in holcyl_list:
if elem.part == 'bearing':
if maxbeardiam < elem.d_out:
maxbeardiam = elem.d_out
return maxbeardiam
# From a group of bearings and washers to make idle pulleys, obtains
# the height
def getgroupheight(holcyl_list):
group_h = 0
for elem in holcyl_list:
group_h += elem.thick
return group_h
def getmaxwashthick(holcyl_list):
"""
From a group of bearings and washers to make idle pulleys, obtains
the diameter of the larger washer
"""
maxwashthick = 0
for elem in holcyl_list:
if elem.part == 'washer':
if maxwashthick < elem.thick:
maxwashthick = elem.thick
return maxwashthick
def get_pulleybelt_h(holcyl_list):
"""
From a list of bearings and washers to make idle pulleys, obtains
the height of the pulley for the belt, which is the height of the bearing
plus the height of the 2 regular washers:
.......
..........:.....:........ bolt head
: Holder for the pulley group
....._________________...:
|_________________|.......large washer..........
|_________| regular washer :
| | bearing + pulleybelt_h
|_________| :
___|_________|___........regular washer.......:
....|_________________|.. large washer
:
.........................: Holder for the pulley group
:.....: nut
:.: bolt shank
Parameters:
-----------
holcyl_list: List of HollowCyl objects (defined in kcomp)
Return:
-------
The height of the part of objects for the belt
"""
pulleybelt_h = 0
for (ind, elem) in enumerate(holcyl_list):
if elem.part == 'bearing':
pulleybelt_h += elem.thick
pulleybelt_h += prev_elem.thick # the previous washer
break
prev_elem = elem
ind += 1 # the next element to the bearing: the washer
pulleybelt_h += holcyl_list[ind].thick
return pulleybelt_h
# doc = FreeCAD.newDocument()
# hcyl0 = kcomp.HollowCyl (part = 'washer', size = 6, kind= 'large')
# hcyl1 = kcomp.HollowCyl (part = 'washer', size = 4, kind= 'regular')
# hcyl2 = kcomp.HollowCyl (part = 'bearing', size = 624) # 624ZZ
# hcyl3 = kcomp.HollowCyl (part = 'washer', size = 4, kind= 'regular')
# hcyl4 = kcomp.HollowCyl (part = 'washer', size = 6, kind= 'large')
# hcyl5 = kcomp.HollowCyl (part = 'washer', size = 4, kind= 'large')
# pul_list = [hcyl0,hcyl1,hcyl2,hcyl3,hcyl4, hcyl5]
# pul_0 = BearWashGroup (holcyl_list = pul_list,
# name = 'idelpul_0',
# normal = VZ,
# pos = FreeCAD.Vector(0,0,0))
# doc.recompute()