forked from Codered741/iLogic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmart Part Config.txt
More file actions
425 lines (359 loc) · 16.6 KB
/
Smart Part Config.txt
File metadata and controls
425 lines (359 loc) · 16.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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
'AUTHOR: Cody Redding
'CONTACT: Codered741@gmail.com
Sub Main()
'Declarations
Dim oDoc As Document = ThisApplication.ActiveEditDocument
'Catch if run from drawing or IPN
If oDoc.DocumentType = 12292 Then 'kDrawingDocumentObject
MessageBox.Show("This rule can only be run in Assemblies and Parts. Please try again. ", "Model Only Rule")
Exit Sub
End If
'Get the correct component definition based on the document type.
Dim oCompDef as Object
If oDoc.DocumentType = 12291 Then 'kAssemblyDocumentObject
oCompDef = CType(oDoc.ComponentDefinition, AssemblyComponentDefinition)
Else If oDoc.DocumentType = 12290 Then 'kPartDocumentObject
oCompDef = CType(oDoc.ComponentDefinition, PartComponentDefinition)
End If
Dim oUOM As UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim oUOMstr As String = oUOM.GetStringFromType(oUOM.LengthUnits) 'for user prompt
Dim oUnitsEnum as Integer = oUom.LengthUnits
Dim sizes As New List(Of Double)
Dim LString as String
Dim WString as String
Dim TString as String
Dim VersionNum as String = "2.2.4"
Dim oCommandMgr As CommandManager = ThisApplication.CommandManager
Dim MsgComp as String = ""
Dim PropAddTries as Integer = 0
oCommandMgr.ControlDefinitions.Item("VaultCheckout").Execute 'Check out file
'Enforce the correct Application Options (Content Center)
ThisApplication.ContentCenterOptions.SetAccessOption(81154)
'kInventorDesktopAccess = 81153
'kVaultOrProductstreamServerAccess = 81154
ThisApplication.ContentCenterOptions.CustomFamilyAsStandard() = True
'Enforce an Isometric view for thumbnails
' this is default for most parts, but specifically added for Frame Generator tubes, as content center parts generally have an image of the profile
oDoc.SetThumbnailSaveOption(79874) 'ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave
customPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
DesignPropertySet = oDoc.PropertySets.Item("Design Tracking Properties")
SummaryPropertySet = oDoc.PropertySets.Item("Inventor Summary Information")
'Define iProperties to reference
Dim pOPS
Dim pMB
Dim pSP
Dim pWidth
Dim pLength
Dim pThick
Dim pMatNum
Dim pMatDesc
Dim pSPVer
Dim pDetailer
Start:
Try 'Get custom iProperties, run property add rule if not found
pOPS = customPropertySet.Item("OPS")
pMB = customPropertySet.Item("MakeBuy")
pSP = customPropertySet.Item("SP")
pWidth = customPropertySet.Item("WIDTH")
pLength = customPropertySet.Item("LENGTH")
pThick = customPropertySet.Item("THICKNESS")
pMatNum = customPropertySet.Item("MATERIAL NUMBER")
pMatDesc = customPropertySet.Item("MATERIAL DESCRIPTION")
pSPVer = customPropertySet.Item("SPVer")
pDetailer = customPropertySet.Item("DETAILER")
Catch
iLogicVB.RunExternalRule("Smart Part Property Add.Txt")
usrCancel = MessageBox.Show("Properties were added, please double check your entries. ", "iLogic Property Check", MessageBoxButtons.OKCancel)
If usrCancel = vbCancel Or PropAddTries > 2 Then ' exit potential infinite loop if property add rule errors more than twice or user cancels.
Exit Sub
End If
PropAddTries += 1
Goto Start
End Try
PropAddTries = 0
If Not pSPVer.Value = VersionNum Then
iLogicVB.RunExternalRule("Smart Part Property Add.Txt")
usrCancel = MessageBox.Show("Properties were added, please double check your entries. ", "iLogic Property Check", MessageBoxButtons.OKCancel)
If usrCancel = vbCancel Or PropAddTries > 2 Then ' exit potential infinite loop if property add rule errors more than twice or user cancels.
Exit Sub
End If
PropAddTries += 1
Goto Start
End If
'Design iProperties
Dim pPN = DesignPropertySet.Item("Part Number")
Dim pCheckedDate = DesignPropertySet.Item("Date Checked")
Dim pApprovedDate = DesignPropertySet.Item("Engr Date Approved")
Dim pCreateDate = DesignPropertySet.Item("Creation Time")
Dim pDesc = DesignPropertySet.Item("Description")
'Summary iProperties
Dim pRev = SummaryPropertySet.Item("Revision Number")
'Get the log file and prepare to write
Dim oAppend As System.IO.StreamWriter
Dim oFile As String = "Z:\Inventor Data\splog.log"
Dim noWrite as Boolean = False
'Check for access to the log file, diasble writing if no access
Try
oAppend = IO.File.AppendText(oFile)
Catch
noWrite = True
End Try
'Write header info to log if access to log is enabled
If noWrite = False Then
oAppend.Write(ThisApplication.UserName & "," & DateTime.Now.ToString("G") & "," & DocumentFileNameExt(oDoc) & ",")
End If
'/////////////////////////////////////////////////////// Checks for correct formatting
'Check for the correct file type, and that file is saved.
If oDoc.DocumentType = kDrawingDocumentObject Then
MessageBox.Show("Smart Part Config can only be run in a Part or Assembly", "File Type Error")
If noWrite = False Then
oAppend.WriteLine("ERROR Drawing Document")
oAppend.Flush()
oAppend.Close()
End If
Exit Sub
End If
If oDoc.DocumentType = kPresentationDocumentObject Then
MessageBox.Show("Smart Part Config can only be run in a Part or Assembly", "File Type Error")
If noWrite = False Then
oAppend.WriteLine("ERROR Presentation Document")
oAppend.Flush()
oAppend.Close()
End If
Exit Sub
End If
If oDoc.FileSaveCounter < 1 Then
MessageBox.Show("File is not saved. Please save and try again. ", "Rule Error",MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If oDoc.FullFileName.Length > 200 Then
MessageBox.Show("This file is saved in a folder path that is too long for Vault. " & vbLf & _
"Please reduce the depth of the folder structure, or shorten the folder name lengths. " & vbLf & _
"This Part was not configured. See a Vault Admin for more information. ", "Total File Length Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
If noWrite = True
oAppend.WriteLine("ERROR Total File Length")
oAppend.Flush()
oAppend.Close()
End If
Exit Sub
End If
'Check if File Name and Part Number Match
If pPN.Value <> DocumentFileName(oDoc) Then
answer = MessageBox.Show("The Part Number and File Name of the current file do not match. " & vbLf & _
"For best results, please correct the part number. "& vbLf & _
"Would you like to change the part number to match the current file name, " & DocumentFileName(oDoc) & " ?", "File\Part Number Mismatch", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)
MsgComp = MsgComp & "ERROR File\Part Number Mismatch|"
If answer = vbCancel Then
Exit Sub
Else If answer = vbYes Then
pPN.Value = DocumentFileName(oDoc)
Else
MessageBox.Show("Please rename the file in Vault so the part number and file name match. ", "File\Part Number Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
'Check Part Number Length
If Len(pPN.Value) > 50 Then
MessageBox.Show("The entered part number is longer than 50 characters, and cannot be entered in Epicor. " & vbLf & _
"Please ensure that the part description in not included in the Part Number field. Please correct and re-run config. ", "Smart Part Config",MessageBoxButtons.OK, MessageBoxIcon.Error)
If noWrite = False
oAppend.WriteLine("Part Number Length Error")
oAppend.Flush()
oAppend.Close()
End If
Exit Sub
End If
If Len(pMatNum.Value) > 50 Then
MessageBox.Show("The entered Material Number is longer than 50 characters, and cannot be entered in Epicor. " & vbLf & _
"Please correct and re-run config. ", "Smart Part Config",MessageBoxButtons.OK, MessageBoxIcon.Error)
If noWrite = False
oAppend.WriteLine("Material Number Length Error")
oAppend.Flush()
oAppend.Close()
End If
Exit Sub
End If
'///////////////////////////////////////////////////////
'Begin configuration
'Auto-fill Vendor Supplied Material value
If Parameter("VendorSupplyMtl") = True Then
pMatNum.Value = "--Vendor Supplied--"
End If
'Check for invalid Revision number
Try
rev = CInt(pRev.Value)
Catch
pRev.Value = "0"
MsgBox("Invalid revision number detected. Only numerical revisions are allowed. Revision has been changed to 0. ")
MsgComp = MsgComp & "ERROR Revision Number|"
End Try
If pDetailer.Value = "" Then
ruDetailer = MessageBox.Show("Are you detailing this part?", "iLogic", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If ruDetailer = vbYes Then
pDetailer.Value = ThisApplication.UserName
End If
End If
'Configure tapped hole modeling parameters
oDoc.ModelingSettings.TappedHoleDiameter = 21764 'Tap Drill
'kThreadMajorDiameter = 21761
'kThreadMinorDiameter = 21762
'kThreadPitchDiameter = 21763
'kThreadTapDrillDiameter = 21764
If oDoc.UnitsOfMeasure.LengthDisplayPrecision <> 3 Then
MsgBox("The document precision was incorrect. Check yo holes!")
oDoc.UnitsOfMeasure.LengthDisplayPrecision = 3.123
End If
' Set 'make' or 'buy'
If Parameter("MB") = False Then
pMB.Value = "Buy"
' pOPS.Value = "" 'removed for e-parts, to allow OPS while remaning a "buy" (publish to method)
oCompDef.BOMStructure = 51973 'Set buys to 'purchased' BOM structure
Else
pMB.Value = "Make"
oCompDef.BOMStructure = 51970 'Set makes to 'normal' BOM structure
End If
'concatenate Operations from parameters, to iProperty
If Parameter("OP1") <> " " Then
pOPS.Value = Parameter("OP1")
Else
pOPS.Value = ""
End If
If Parameter("OP2") <> " " Then
pOPS.Value = pOPS.Value & Parameter("OP2")
Else
pOPS.Value = pOPS.Value & ""
End If
If Parameter("OP3") <> " " Then
pOPS.Value = pOPS.Value & Parameter("OP3")
Else
pOPS.Value = pOPS.Value & ""
End If
If Parameter("OP4") <> " " Then
pOPS.Value = pOPS.Value & Parameter("OP4")
Else
pOPS.Value = pOPS.Value & ""
End If
'check for outsource OPS and prompt user for correct material entry
If pMB.Value = "Make" Then
If Parameter("OP1").Contains("OS") AndAlso Parameter("VendorSupplyMtl") = False Then
MessageBox.Show("Are you sure you need to supply material for the Outsource operation(s)? " & vblf & _
"If you do not need to supply material, please check the 'Vendor Supplied Material' check box, and re-run 'Smart Part Config'. " & vbLf & _
"If you are not sure, check with your studio lead or the purchasing departament. ","Material Error?", MessageBoxButtons.OK, MessageBoxIcon.Warning)
MsgComp = MsgComp & "ERROR Material 1|"
End If
If Parameter("VendorSupplyMtl") = False AndAlso Len(pMatDesc.Value) = 0 OrElse Len(pMatNum.Value) = 0 Then
MessageBox.Show("You have not entered a Material Number or Description. " & vbLF & _
" All 'Make' parts require an entry in Material Number and Material Description. " & vbLf & _
"Please enter a material number for this part or, if the part is to be outsourced, check 'Vendor Supplied Material' and re-run the config. ", "Material Number Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
MsgComp = MsgComp & "ERROR Material 2|"
End If
If NOT Parameter("OP1").Contains("OS") AndAlso Len(Parameter("OP1")) > 5 AndAlso Parameter("VendorSupplyMtl") = True Then
MessageBox.Show("Parts that are made in house require material to be made from. " & vblf & _
"Please uncheck 'Vendor Supplied Material' and enter a material number, or change the operations. " & vbLf & _
"If you are not sure, check with your studio lead or the purchasing departament. ","Material Error?", MessageBoxButtons.OK, MessageBoxIcon.Warning)
MsgComp = MsgComp & "ERROR Material 3|"
End If
'Router Material Checks
If Parameter("OP1").Contains("OP011") Then
If pMatDesc.Value.ToLower.Contains("bar") OrElse pMatDesc.Value.ToLower.Contains("tube") Then
MessageBox.Show("Please check your material selection. Only Sheet/Plate materials are suitable for the Router. ", "Router Material Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
MsgComp = MsgComp & "ERROR Router Material 1|"
End If
End If
If Parameter("OP1").Contains("OP011") Then
If pMatDesc.Value.ToLower.Contains("steel") Then
MessageBox.Show("Please check your material selection. Only Wood/Plastic/Aluminum materials are suitable for the Router. ", "Router Material Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
MsgComp = MsgComp & "ERROR Router Material 2|"
End If
End If
'Mill Material Checks
If Parameter("OP1").Contains("OP010") Then
If pMatDesc.Value.ToLower.Contains("sheet") OrElse pMatDesc.Value.ToLower.Contains("plate") Then
MessageBox.Show("Please check your material selection. Sheet/Plate materials are not suitable for the Mill. " & vbLF & _
"Plates and Sheets must be cut by Router/Laser/Waterjet before they can be milled. ", _
"Mill Material Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
MsgComp = MsgComp & "ERROR Mill Material 1|"
End If
End If
If Parameter("OP1").Contains("OP010") Then
If pMatDesc.Value.ToLower.Contains("wood") Then
MessageBox.Show("Please check your material selection. Wood materials are not suitable for the Mill. ", "Router Material Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
MsgComp = MsgComp & "ERROR Mill Material 2|"
End If
End If
End If
'This should move to a new rule. ????????
'Look for a configuration that appears to be an epart, and suggest adding ops, if necessary
Dim epart as Boolean = True
Dim debug as Boolean = True
If pPN.Value.Length >= 7 AndAlso pMB.Value = "Buy" AndAlso pOPS.Value.Length > 5 Then
epart = InputRadioBox("Are you making an Epicor Manufactured Part?", "Yes, Products RULE!", "No, I hate saving money. ", epart, "iLogic")
If epart = True Then
pOPS.Value = "OP027:CNC Program~" & pOPS.Value
ErrComp = ErrComp & "EPart|"
'Prompt "Is this a control part"
cpart = InputRadioBox("Is this a Control Part?", "Yes, im awesome", "No, im a loser", True, "Control Rules" )
If cpart = True Then
pOPS.Value = pOPS.Value & "OP062:Control – Fabrication~"
ErrComp = ErrComp & "Control EPart|"
End If
MsgBox("Operations appended. Remember to mark the last operation as ""Final"". " & vbLf & _
"If the part has in-house router or mill operations, check the iProperties for time estimates. ")
End If
Else
'MsgBox("This part is not correctly configured to be an Epicor part. "
End If
'measure bounding box, flat pattern for sheet metal parts.
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then ' Determine if part is Sheet Metal
'Measure part and write to parameters, if sheet metal
Parameter("XDIM") = SheetMetal.FlatExtentsLength
Parameter("YDIM") = SheetMetal.FlatExtentsWidth
Parameter("ZDIM") = Parameter("Thickness")
Else
'Measure part and write to parameters, if standard
Parameter("XDIM") = Measure.ExtentsLength
Parameter("YDIM") = Measure.ExtentsWidth
Parameter("ZDIM") = Measure.ExtentsHeight
End If
'Pulls measurements into list and sorts according to size
sizes.Add(Parameter("XDIM"))
sizes.Add(Parameter("YDIM"))
sizes.Add(Parameter("ZDIM"))
sizes.Sort()
'Outputs 2 largest dimensions to strings to lose units, converting the units from the file units to inches,
'then write to iProperty
pLength.Value = String.Format(Round(oUOM.ConvertUnits(sizes(2), oUnitsEnum, 11272), 1))
pWidth.Value = String.Format(Round(oUOM.ConvertUnits(sizes(1), oUnitsEnum, 11272), 1))
pThick.Value = String.Format(Round(oUOM.ConvertUnits(sizes(0), oUnitsEnum, 11272), 1))
'Auto Fill creation date field with todays date
pCreateDate.Value = DateString
pApprovedDate.Value = DateString
pCheckedDate.Value = DateString
'Set BOM Quantity to each (Frame generator length based parts)
oCompDef.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity)
'run rule to fill values for machining estimation
If ThisApplication.UserName = "Cody Redding" Then
iLogicVb.RunExternalRule("Time Estimate.iLogicVb") 'not ready for primetime
'MsgBox("You are AWESOME!")
End If
'Save Document
ThisDoc.Save
'Write out part values, if writing is enabled.
If noWrite = False
oAppend.WriteLine(pPN.Value & "," & pRev.Value & "," & pDesc.Value.Replace(",", "_") & "," & pMB.Value & "," & _
pLength.Value & "," & pWidth.Value & "," & pThick.Value & "," & pMatNum.Value.Replace(",", "_") & "," & _
pMatDesc.Value.Replace(",", "_") & "," & Parameter("OP1") & "," & Parameter("OP2") & "," & Parameter("OP3") & "," & _
Parameter("OP4") & "," & MsgComp)
oAppend.Flush()
oAppend.Close()
End If
End Sub
'/////////////////////////////////////Functions////////////////////////////////////////////////////////////
Function DocumentFileName(Doc As Document) As String
Dim FilePath as String
FilePath = Doc.FullFileName
DocumentFileName = IO.Path.GetFileNameWithoutExtension(FilePath)
'MsgBox(DocumentFileName)
End Function
Function DocumentFileNameExt(Doc as Document) As String
DocumentFileNameExt = IO.Path.GetFileName(Doc.FullFileName)
End Function