-
Notifications
You must be signed in to change notification settings - Fork 16
/
xEndIdlerPlate.py
275 lines (239 loc) · 12 KB
/
xEndIdlerPlate.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
# Copyright 2015 Matthew Rogge
#
# This file is part of Retr3d.
#
# Retr3d is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Retr3d is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Retr3d. If not, see <http://www.gnu.org/licenses/>.
#import Math stuff
from __future__ import division # allows floating point division from integersimport math
import math
from itertools import product
#import FreeCAD modules
import FreeCAD as App
import Part
import Sketcher
import Draft
#Specific to printer
import globalVars as gv
import utilityFunctions as uf
#notes
#Nut facetoface top and bottom should be resolved into a max
class XEndIdlerPlate(object):
def __init__(self):
pass
def assemble(self):
App.ActiveDocument=App.getDocument("xEndIdlerPlate")
shape = App.ActiveDocument.ActiveObject.Shape
App.ActiveDocument=App.getDocument("PrinterAssembly")
App.ActiveDocument.addObject('Part::Feature','xEndIdlerPlate').Shape= shape
#Color Part change colors to metal
#Rotate into correct orientation
rotateAngle = -90
rotateCenter = App.Vector(0,0,0)
rotateAxis = App.Vector(1,0,0)
Draft.rotate([App.ActiveDocument.xEndIdlerPlate],rotateAngle,rotateCenter,axis = rotateAxis,copy=False)
#Define shifts and move the left clamp into place
xShift = gv.xRodLength/2-gv.xRodClampPocketDepth
yShift = (gv.extruderNozzleStandoff
- gv.zRodStandoff
- gv.xEndZRodHolderFaceThickness
- gv.xEndZRodHolderMaxNutFaceToFace/2
- gv.xMotorMountPlateThickness)
zShift = gv.xMotorMountPlateWidth+ (gv.xRodSpacing-gv.xMotorMountPlateWidth)/2
App.ActiveDocument=App.getDocument("PrinterAssembly")
Draft.move([App.ActiveDocument.xEndIdlerPlate],App.Vector(xShift, yShift, zShift),copy=False)
App.ActiveDocument.recompute()
shape = App.ActiveDocument.xEndIdlerPlate
if shape not in gv.xAxisParts:
gv.xAxisParts.append(shape)
def draw(self):
#helper Variables
xRodClampMountHoleSpacingVert = gv.xRodSpacing-2*gv.xRodAxisToMountHoleDist
xRodClampMountHoleSpacingHoriz = gv.xRodClampWidth-2*gv.xRodClampEdgeToMountHoleDist
#safety check
#xRodSpacing must be wide enough for the motor to be mounted between the rods
#Make file and build part
try:
App.getDocument('xEndIdlerPlate').recompute()
App.closeDocument("xEndIdlerPlate")
App.setActiveDocument("")
App.ActiveDocument=None
except:
pass
App.newDocument("xEndIdlerPlate")
App.setActiveDocument("xEndIdlerPlate")
App.ActiveDocument=App.getDocument("xEndIdlerPlate")
#Make the plate
#Sketch points
p1x = 0
p1y = 0
p2x = 0
p2y = gv.xMotorMountPlateWidth
p3x = gv.xRodClampWidth
p3y = gv.xMotorMountPlateWidth
p4x = gv.xRodClampWidth
p4y = 0
#Make Sketch
App.activeDocument().addObject('Sketcher::SketchObject','Sketch')
App.activeDocument().Sketch.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(0.000000,0.000000,0.000000,1.000000))
App.ActiveDocument.Sketch.addGeometry(Part.Line(App.Vector(p1x,p1y,0),App.Vector(p2x,p2y,0)))
App.ActiveDocument.Sketch.addGeometry(Part.Line(App.Vector(p2x,p2y,0),App.Vector(p3x,p3y,0)))
App.ActiveDocument.Sketch.addGeometry(Part.Line(App.Vector(p3x,p3y,0),App.Vector(p4x,p4y,0)))
App.ActiveDocument.Sketch.addGeometry(Part.Line(App.Vector(p4x,p4y,0),App.Vector(p1x,p1y,0)))
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1))
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1))
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',2,2,3,1))
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',3,2,0,1))
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Vertical',0))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Vertical',2))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Horizontal',3))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Horizontal',1))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',0,1,-1,1))
App.ActiveDocument.recompute()
#Add dimensions
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('DistanceX',3,-gv.xRodClampWidth))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('DistanceY',2,-gv.xMotorMountPlateWidth))
App.ActiveDocument.recompute()
App.getDocument('xEndIdlerPlate').recompute()
#extrude x motor mount plate
App.activeDocument().addObject("PartDesign::Pad","Pad")
App.activeDocument().Pad.Sketch = App.activeDocument().Sketch
App.activeDocument().Pad.Length = 10.0
App.ActiveDocument.recompute()
App.ActiveDocument.Pad.Length = gv.xMotorMountPlateThickness
App.ActiveDocument.Pad.Reversed = 0
App.ActiveDocument.Pad.Midplane = 0
App.ActiveDocument.Pad.Length2 = 100.000000
App.ActiveDocument.Pad.Type = 0
App.ActiveDocument.Pad.UpToFace = None
App.ActiveDocument.recompute()
#cut holes for xRodClamp
#Sketch Points
p1x = 0
p1y = gv.xMotorMountPlateWidth/2
p2x = gv.xRodClampWidth
p2y = gv.xMotorMountPlateWidth/2
p3x = gv.xRodClampEdgeToMountHoleDist
p3y = gv.xRodAxisToMountHoleDist
p4x = gv.xRodClampEdgeToMountHoleDist
p4y = gv.xMotorMountPlateWidth-gv.xRodAxisToMountHoleDist
p5x = gv.xRodClampWidth-gv.xRodClampEdgeToMountHoleDist
p5y = gv.xMotorMountPlateWidth-gv.xRodAxisToMountHoleDist
p6x = gv.xRodClampWidth-gv.xRodClampEdgeToMountHoleDist
p6y = gv.xRodAxisToMountHoleDist
p7x = gv.xRodClampEdgeToMountHoleDist
p7y = gv.xMotorMountPlateWidth/2
p8x = gv.xRodClampWidth/2
p8y = gv.xMotorMountPlateWidth/2
#Make sketch
App.activeDocument().addObject('Sketcher::SketchObject','Sketch001')
App.activeDocument().Sketch001.Support = uf.getFace(App.ActiveDocument.Pad,
None, None,
None, None,
gv.xMotorMountPlateThickness, 0)#(App.ActiveDocument.Pad,["Face6"])
App.activeDocument().recompute()
App.ActiveDocument.Sketch001.addExternal("Pad",uf.getEdge(App.ActiveDocument.Pad,
0,0,
gv.xMotorMountPlateWidth/2,0,
gv.xMotorMountPlateThickness,0))
App.ActiveDocument.Sketch001.addExternal("Pad",uf.getEdge(App.ActiveDocument.Pad,
gv.xRodClampWidth,0,
gv.xMotorMountPlateWidth/2,0,
gv.xMotorMountPlateThickness,0))
App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p1x,p1y,0),App.Vector(p2x,p2y,0)))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('PointOnObject',0,1,-3))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('PointOnObject',0,2,-4))
App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p3x,p3y,0),App.Vector(p4x,p4y,0)))
App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p4x,p4y,0),App.Vector(p5x,p5y,0)))
App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p5x,p5y,0),App.Vector(p6x,p6y,0)))
App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p6x,p6y,0),App.Vector(p3x,p3y,0)))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',2,2,3,1))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',3,2,4,1))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',4,2,1,1))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Horizontal',2))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Horizontal',4))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Vertical',1))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Vertical',3))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.toggleConstruction(0)
App.ActiveDocument.Sketch001.toggleConstruction(4)
App.ActiveDocument.Sketch001.toggleConstruction(3)
App.ActiveDocument.Sketch001.toggleConstruction(2)
App.ActiveDocument.Sketch001.toggleConstruction(1)
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addGeometry(Part.Point(App.Vector(p7x,p7y,0)))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('PointOnObject',5,1,1))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('PointOnObject',5,1,0))
App.ActiveDocument.Sketch001.addGeometry(Part.Circle(App.Vector(p3x,p3y,0),App.Vector(0,0,1),gv.mountToPrintedDia/2))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',1,1,6,3))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addGeometry(Part.Circle(App.Vector(p4x,p4y,0),App.Vector(0,0,1),gv.mountToPrintedDia/2))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',7,3,1,2))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addGeometry(Part.Circle(App.Vector(p5x,p5y,0),App.Vector(0,0,1),gv.mountToPrintedDia/2))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',2,2,8,3))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addGeometry(Part.Circle(App.Vector(p6x,p6y,0),App.Vector(0,0,1),gv.mountToPrintedDia/2))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',9,3,3,2))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Equal',6,7))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Equal',7,8))
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Equal',8,9))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addGeometry(Part.Circle(App.Vector(p8x,p8y,0),App.Vector(0,0,1),gv.xEndIdlerHoleDia/2))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('PointOnObject',10,3,0))
App.ActiveDocument.recompute()
#add dimensions
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('DistanceX',4, -xRodClampMountHoleSpacingHoriz))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Distance',3,2,-4,gv.xRodClampEdgeToMountHoleDist))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('DistanceY',3,-xRodClampMountHoleSpacingVert))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Radius',8,gv.mountToPrintedDia/2))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Radius',10,gv.xEndIdlerHoleDia/2))
App.ActiveDocument.recompute()
#add Symmetric constraints
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Symmetric',1,1,1,2,5,1))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Symmetric',1,1,2,2,10,3))
App.ActiveDocument.recompute()
App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Symmetric',-1,1,-3,2,0,1))
App.ActiveDocument.recompute()
#exit sketch
App.getDocument('xEndIdlerPlate').recompute()
#Cut holes through all
App.activeDocument().addObject("PartDesign::Pocket","Pocket")
App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
App.activeDocument().Pocket.Length = 5.0
App.ActiveDocument.recompute()
App.ActiveDocument.Pocket.Length = 5.000000
App.ActiveDocument.Pocket.Type = 1
App.ActiveDocument.Pocket.UpToFace = None
App.ActiveDocument.recompute()
#set view as axiometric