forked from Codered741/iLogic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime Estimate.iLogicVB
More file actions
383 lines (295 loc) · 10.6 KB
/
Copy pathTime Estimate.iLogicVB
File metadata and controls
383 lines (295 loc) · 10.6 KB
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
'AUTHOR: Cody Redding
'CONTACT: Codered741@gmail.com
'FUNCTION:
'Provides machining time estimates to Epicor via file parameters
Sub Main()
SharedVariable("LogVar") = "Time Estimate"
iLogicVB.RunExternalRule("Write SV to Log.iLogicVB")
Dim Debug as Boolean = False 'enable debug mode
Dim oDoc As Document = ThisApplication.ActiveEditDocument
Dim oCompDef as PartComponentDefinition
Dim userProps as PropertySet
Dim pOPS
Dim pMtlRem
Dim pHoles
Dim pHolesTap
Dim pEdges
Dim pMilledFaceCount
Dim pPerim
Dim pMaterial
Dim pRoutTime
Dim pMillTime
Dim MillingTime As Double
Dim DrillTime As Double
Dim TapTime As Double
Dim FlipTime As Double
Dim MillSetup As Double
Dim SetupTime As Double
Dim ProgramTime As Double
Dim ComplexMult As Double
Dim MillPerPart As Double
If IsPrt(oDoc) = True Then
Try
oCompDef = oDoc.ComponentDefinition
userProps = oDoc.PropertySets.Item("Inventor User Defined Properties")
pOPS = userProps.Item("OPS")
pMtlRem = userProps.Item("MATERIAL REMOVED")
pHoles = userProps.Item("Holes")
pHolesTap = userProps.Item("HolesTapped")
pEdges = userProps.Item("Edge Count")
pMilledFaceCount = userProps.Item("MilledFaceCount")
pPerim = userProps.Item("Perimeter")
pMaterial = userProps.Item("MATERIAL DESCRIPTION")
pRoutTime = userProps.Item("RoutTime")
pMillTime = userProps.Item("MillTime")
Catch
iLogicVB.RunExternalRule("Smart Part Property Add.txt")
MsgBox("Properties were not added, please try again. ", ,"Time Estimate Error")
Exit Sub
End Try
pHoles.Value = GetHolesQty(oCompDef)
pHolesTap.Value = GetHolesTapQty(oCompDef)
pEdges.Value = EdgeCounts(oDoc)
pMtlRem.Value = MaterialRemoved(oDoc, Parameter("XDIM"), Parameter("YDIM"), Parameter("ZDIM"))
'Get Setup counts for Mill OPS
If pOPS.Value.Contains("OP010") AndAlso Not Debug Then
pMilledFaceCount.Value = 0
pPerim.Value = 0
While pMilledFaceCount.Value < 1 OrElse pMilledFaceCount.Value > 6
pMilledFaceCount.Value = InputBox("Please enter the number of Milled Faces (1-6)", "Mill OP Detected", "0")
If pMilledFaceCount.Value < 1 OrElse pMilledFaceCount.Value > 6 Then
MsgBox("Please enter a value between 1 and 6")
End If
End While
Else
pMilledFaceCount.Value = 0
End If
ComplexMult = ComplexityModifier(pEdges.Value)
'Estimate Time to remove material, defaults to steel value unless aluminum is detected.
If pMaterial.Value.ToLower.Contains("aluminum") OrElse pMaterial.Value.ToLower.Contains("plastic") OrElse pMaterial.Value.ToLower.Contains("wood") AndAlso pMilledFaceCount.Value > 0 Then 'CHECK CASE
MillingTime = (pMtlRem.Value / 0.3616)*ComplexMult
Else 'If pMaterial.Value.Contains("Steel")
MillingTime = (pMtlRem.Value / 0.1448)*ComplexMult
End If
DrillTime = pHoles.Value * 30
TapTime = pHolesTap.Value * 30
FlipTime = pMilledFaceCount.Value * 30
If pMilledFaceCount.Value > 0 Then
pMillTime.Value = Round((MillingTime + DrillTime + TapTime + FlipTime)/60, 2)
Else
pMillTime.Value = 0
End If
'Get perimeter for router ops
If pOPS.Value.Contains("OP011") AndAlso Not Debug Then
MsgBox("Please select the bottom router face. ", Title := "Router OP detected")
pPerim.Value = GetPerimeter(oDoc)
Else
pPerim.Value = 0
End If
'Calculate Estimated Router Time
If pPerim.Value > 0 Then
pRoutTime.Value = Round(pPerim.Value / 100, 2) 'Check this Value
Else
pRoutTime.Value = 0
End If
'//////////////////////////////////TESTING////////////////////////////////////////////
If Debug Then 'Ignore op rules, and display the info for debug purposes.
pMilledFaceCount.Value = 0
pPerim.Value = 0
'Get Machined Sides
pMilledFaceCount.Value = InputBox("Please enter the number of Machined Sides (1-6)", "Mill OP Detected", "0")
MsgBox("Please select the bottom router face. ", Title := "Router OP detected")
pPerim.Value = GetPerimeter(oDoc)
Dim RoutingTime As Double
If pPerim.Value > 0 Then
RoutingTime = Round(pPerim.Value / 100, 2) 'Check this Value
End If
'MsgBox("Routing Time: " & RoutingTime & " min")
If pMilledFaceCount.Value > 0 Then
MillPerPart = Round((MillingTime + DrillTime + TapTime + FlipTime)/60, 2)
Else
MillPerPart = 0
End If
MillSetup = (SetupTime + ProgramTime)/60
MsgBox("Milling Time (per Part): " & MillPerPart & " min" & vbCrLf & _
"Mill Setup (one time): " & MillSetup & " min" & vbCrLf & _
"Routing Time: " & RoutingTime & " min")
'MsgBox("Mill Setup (one time): " & MillSetup & " min")
End If 'Debug
Else
MessageBox.Show("Machining estimation is only valid for parts. ", "Machining Estimation", MessageBoxButtons.OK, MessageBoxIcon.Warning)
' pHoles.Value = 0
' pHolesTap.Value = 0
' pEdges.Value = 0
' pMilledFaceCount.Value = 0
' pPerim.Value = 0
End If
End Sub
Function GetPerimeter(Doc as Document) as Double
' a reference to the part component definition.
' This assumes that a part document is active.
Dim oCompDef As PartComponentDefinition
oCompDef = ThisApplication.ActiveEditDocument.ComponentDefinition
' Get the first face of the model. This sample assumes a simple
' model where at least the first face is a plane. (A box is a good
' test case.)
Dim oFace As Face
oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select bottom face")
' Get one of the edges of the face to use as the sketch x-axis.
Dim oEdge As Edge
oEdge = oFace.Edges.Item(2)
' Get the start vertex of the edge to use as the origin of the sketch.
Dim oVertex As Vertex
oVertex = oEdge.StartVertex
' Create a new sketch. This last argument is to true to cause the
' creation of sketch geometry from the edges of the face.
Dim oSketch As PlanarSketch
oSketch = oCompDef.Sketches.AddWithOrientation(oFace, oEdge, True, True, oVertex, True)
' Change the name.
oSketch.Name = "Router Estimate"
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid
Dim oRegionProps As RegionProperties
oRegionProps = oProfile.RegionProperties
oRegionProps.Accuracy = AccuracyEnum.kMedium
Dim oUOM As UnitsOfMeasure = Doc.UnitsOfMeasure
GetPerimeter = Round(oUOM.ConvertUnits(oRegionProps.Perimeter, "cm", "in"), 2)
oSketch.Delete
End Function
Function EdgeCounts(oPartDoc as PartDocument) As Integer 'Returns the number of edges in the current model
Dim oCompDef As ComponentDefinition = oPartDoc.ComponentDefinition
Dim oSurfaceBodies As SurfaceBodies
Dim oSurfaceBody As SurfaceBody
Try
oSurfaceBodies = oCompDef.SurfaceBodies
oSurfaceBody = oSurfaceBodies(1)
Return oSurfaceBody.Edges.Count
Catch
Return 0
End Try
End Function
Function MaterialRemoved(Doc as Document, XDIM As Double, YDIM As Double, ZDIM As Double) As Double 'Returns Difference between the part bounding box and the part volume
Dim partVol as Double = Doc.ComponentDefinition.MassProperties.Volume
Dim oUOM As UnitsOfMeasure = Doc.UnitsOfMeasure
Dim oLenUnitsEnum as Integer = oUOM.LengthUnits
'Convert Bounding Box Dims to Inches
XDIMin = oUOM.ConvertUnits(XDIM, oLenUnitsEnum, "in")
YDIMin = oUOM.ConvertUnits(YDIM, oLenUnitsEnum, "in")
ZDIMin = oUOM.ConvertUnits(ZDIM, oLenUnitsEnum, "in")
'Convert Part Volume from cubic centimeters to cubic Inches
Dim PartVolIn As Double = oUOM.ConvertUnits(partVol, "cm^3", "inch^3")
Dim BBoxVol as Double = XDIMin * YDIMin * ZDIMin
MtlRemoved = Abs(Round(BBoxVol - PartVolIn, 2))
Return MtlRemoved
End Function
Function GetHolesQty(ByVal oDef As PartComponentDefinition) As Integer
Dim oSurfaceBodies as SurfaceBodies = oDef.SurfaceBodies
Try
Dim oSurfaceBody As SurfaceBody = oSurfaceBodies.Item(1)
Dim oFaces as Faces = oSurfaceBody.Faces
Dim oFace As Face
Dim i As Integer = 0
For Each oFace In oFaces
If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
i = i+1
End If
Next
Return i
Catch
Return 0
End Try
End Function
Function GetHolesTapQty(ByVal oDef As PartComponentDefinition) As Integer
Dim N As Integer = 0 'counter
Dim oHoles As HoleFeatures = oDef.Features.HoleFeatures
For Each oH As HoleFeature In oHoles
If Not oH.Suppressed AndAlso oH.Tapped = True Then
N += oH.HoleCenterPoints.Count
End If
Next
'have we any rectangular patterns ?
Dim oRectPatterns As RectangularPatternFeatures
oRectPatterns = oDef.Features.RectangularPatternFeatures
If oRectPatterns.Count > 0 Then
For Each oRPF As RectangularPatternFeature In oRectPatterns
Dim m As Integer = 0
If Not oRPF.Suppressed Then
If (TypeOf oRPF.ParentFeatures.Item(1) Is HoleFeature) Then
Dim oH As HoleFeature = oRPF.ParentFeatures.Item(1)
If Not oH.Suppressed AndAlso oH.Tapped = True Then
For Each oFPE As FeaturePatternElement In oRPF.PatternElements
If Not oFPE.Suppressed Then m += 1
Next
End If
End If
N += m - 1
Else
N += m
End If
Next
End If
'have we any circular patterns ?
Dim oCircPatterns As CircularPatternFeatures
oCircPatterns = oDef.Features.CircularPatternFeatures
If oCircPatterns.Count > 0 Then
For Each oCPF As CircularPatternFeature In oCircPatterns
Dim m As Integer = 0
If Not oCPF.Suppressed Then
If (TypeOf oCPF.ParentFeatures.Item(1) Is HoleFeature) Then
Dim oH As HoleFeature = oCPF.ParentFeatures.Item(1)
If Not oH.Suppressed AndAlso oH.Tapped = True Then
For Each oFPE As FeaturePatternElement In oCPF.PatternElements
If Not oFPE.Suppressed Then m += 1
Next
End If
End If
N += m - 1
Else
N += m
End If
Next
End If
Return N
End Function
Function isPrt(ThisDoc As Document) As Boolean
Debug.Print (ThisDoc.DocumentType)
If ThisDoc.DocumentType = kPartDocumentObject Then
isPrt = True
Else
isPrt = False
End If
End Function
Function ComplexityModifier(Count as Integer) As Integer
Select Case Count
Case 1 to 100
ComplexityModifier = 1.5
Case 101 to 200
ComplexityModifier = 1.8
Case 201 To 300
ComplexityModifier = 2.1
Case 301 To 400
ComplexityModifier = 2.5
Case 401 To 500
ComplexityModifier = 2.8
Case 501 To 600
ComplexityModifier = 3.4
Case 601 To 700
ComplexityModifier = 4
Case 701 To 800
ComplexityModifier = 5
Case 801 To 900
ComplexityModifier = 6
CAse 901 To 1000
ComplexityModifier = 7
Case 1001 To 1100
ComplexityModifier = 8
Case 1101 To 1200
ComplexityModifier = 8.5
Case 1201 To 1300
ComplexityModifier = 9
Case 1301 To 1400
ComplexityModifier = 9.5
Case Count > 1401
ComplexityModifier = 10
End Select
End Function