-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSmart Part Config.txt
More file actions
560 lines (473 loc) · 22.4 KB
/
Smart Part Config.txt
File metadata and controls
560 lines (473 loc) · 22.4 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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
'AUTHOR: Cody Redding
'CONTACT: Codered741@gmail.com
Imports System.Globalization
Imports System.Diagnostics
Sub Main()
Dim stopWatch as New Stopwatch
stopWatch.Start()
'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.4"
Dim oCommandMgr As CommandManager = ThisApplication.CommandManager
Dim MsgComp as String = ""
Dim PropAddTries as Integer = 0
Try
oCommandMgr.ControlDefinitions.Item("VaultCheckout").Execute 'Check out file
Catch
MsgComp = MsgComp & "Checkout Fail |"
End Try
Dim oModelStates as ModelStates = oCompDef.ModelStates
If oModelStates.Count > 1 And Not oModelStates.MemberEditScope = "57602" And Not oModelStates.ActiveModelState Is "[Primary]" Then
msWarn = MessageBox.Show("Running Smart Part Config from Model States other than [Primary] with 'Edit Factory Scope' disabled can cause unintended issues when publishing. " & vbLf & _
"Click 'Yes' to switch this or 'No' if you know what you are doing. ", "Model States are Tricky!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
If msWarn = vbYes Then
oCompDef.ModelStates.MemberEditScope = "57602" 'kEditAllMembers
oCompDef.ModelStates.Item("[Primary]").Activate
MsgComp = MsgComp & "MS Yes |"
Else
MsgComp = MsgComp & "MS No |"
End If
End If
'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
Dim pLengthmm
Dim pWidthmm
Dim pThickmm
'Ensure the 'Export' box is NOT checked for the LENGTH/WIDTH/THICKNESS parameter. Some CC parts use this property and export it to the parameter. This adds the unit string, which causes an error when publishing.
Try
oCompDef.Parameters.Item("Length").ExposedAsProperty = False
Catch
End Try
Try
oCompDef.Parameters.Item("LENGTH").ExposedAsProperty = False
Catch
End Try
Try
oCompDef.Parameters.Item("WIDTH").ExposedAsProperty = False
Catch
End Try
Try
oCompDef.Parameters.Item("THICKNESS").ExposedAsProperty = False
Catch
End Try
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")
pLengthmm = customPropertySet.Item("LENGTH_mm")
pWidthmm = customPropertySet.Item("WIDTH_mm")
pThickmm = customPropertySet.Item("THICKNESS_mm")
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", New CultureInfo("en-US")) & "," & DocumentFileNameExt(oDoc) & ",") '"MM/dd/yyyy hh:mm:ss tt"
End If
Dim jsonPayload As String
Try
jsonPayload = "{" & """timestamp"":""" & DateTime.UtcNow.ToString("s") & """," & """user"":""" & ThisApplication.UserName & """," & """filename"":""" & DocumentFileNameExt(oDoc) & """," & """modelState"":""" & oModelStates.ActiveModelState.Name & ""","
Catch
jsonPayload = "{" & """timestamp"":""" & DateTime.UtcNow.ToString("s") & """," & """user"":""" & ThisApplication.UserName & """," & """filename"":""" & DocumentFileNameExt(oDoc) & """," & """modelState"":""" & "No Model States" & ""","
End Try
'/////////////////////////////////////////////////////// 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
jsonPayload = jsonPayload & """," & """PartNumberOrMessage"":""" & "ERROR Drawing Document" & "}"
PostLog (jsonPayload)
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
jsonPayload = jsonPayload & """," & """PartNumberOrMessage"":""" & "ERROR Presentation Document" & "}"
PostLog (jsonPayload)
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
jsonPayload = jsonPayload & """," & """PartNumberOrMessage"":""" & "ERROR Total File Length" & "}"
PostLog (jsonPayload)
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
jsonPayload = jsonPayload & """," & """PartNumberOrMessage"":""" & "Part Number Length Error" & "}"
PostLog (jsonPayload)
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
jsonPayload = jsonPayload & """," & """PartNumberOrMessage"":""" & "Material Number Length Error" & "}"
PostLog (jsonPayload)
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
Try
'Configure tapped hole modeling parameters
oDoc.ModelingSettings.TappedHoleDiameter = 21764 'Tap Drill
'kThreadMajorDiameter = 21761
'kThreadMinorDiameter = 21762
'kThreadPitchDiameter = 21763
'kThreadTapDrillDiameter = 21764
Catch
MessageBox.Show("There was an error in setting the Modeling of tapped holes. Contact #help_inventor for assistance. The rule will continue.", "Tapped Hole Modeling Error", MessageBoxButtons.OK)
End Try
If oDoc.UnitsOfMeasure.LengthDisplayPrecision < 3 Then
oDoc.UnitsOfMeasure.LengthDisplayPrecision = 3.123
MsgBox("The document precision was incorrect. Check yo holes!")
MsgComp = MsgComp & "ERROR Tapped Hole Setting|"
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
'/////////////////////TODO////////////////////////////////////
'Check if OPS were filled manually, parse the ops, and set parameters
'If pOPS.Value Is Not Nothing And If Parameter("OP1") is Nothing Then
'parse pOPS.value into list of strings, by ~'s
'search parameter values for OPS
'assign the parameters to the operations specified.
'concatenate Operations from parameters, write 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
'Look for a configuration that appears to be an epart, and suggest adding ops, if necessary
'OBSOLETE as of 20251203 - No operations are to be appended for eparts
' Dim epart as Boolean = True
' If pPN.Value.Length >= 7 AndAlso pMB.Value = "Buy" AndAlso pOPS.Value.Length > 5 Then
' epart = MessageBox.Show("Are you making an Epicor Manufactured Part?", "Methodized Part?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) 'InputRadioBox("Are you making an Epicor Manufactured Part?", "Yes, Products RULE!", "No, I hate saving money. ", epart, "iLogic")
' If epart = vbYes Then
' MsgComp = MsgComp & "EPart|"
' 'Prompt "Is this a control part"
' cpart = MessageBox.Show("Is this a Control Part?", "Append Control Fab?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) 'InputRadioBox("Is this a Control Part?", "Yes, im awesome", "No, im a loser", True, "Control Rules" )
' If cpart = vbYes Then
' pOPS.Value = pOPS.Value & "OP062:Control – Fabrication~"
' MsgComp = MsgComp & "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))
pLengthmm.Value = String.Format(Round(oUOM.ConvertUnits(sizes(2), oUnitsEnum, 11269), 1))
pWidthmm.Value = String.Format(Round(oUOM.ConvertUnits(sizes(1), oUnitsEnum, 11269), 1))
pThickmm.Value = String.Format(Round(oUOM.ConvertUnits(sizes(0), oUnitsEnum, 11269), 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)
'Reset parameters to enforce consistency across model states, if enabled.
If oModelStates.MemberEditScope = "57602" Then
pPN.Value = pPN.Value
pDesc.Value = pDesc.Value
pMB.Value = pMB.Value
pMatNum.Value = pMatNum.Value
pMatDesc.Value = pMatDesc.Value
pOPS.Value = pOPS.Value
pRev.Value = pRev.Value
Parameter("MB") = Parameter("MB")
Parameter("OP1") = Parameter("OP1")
Parameter("OP2") = Parameter("OP2")
Parameter("OP3") = Parameter("OP3")
Parameter("OP4") = Parameter("OP4")
End If
'Save Document
Try
ThisDoc.Save
Catch
MessageBox.Show("Unable to save file. Please make sure the file is checked out, and save the file. ", "Write Access Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
'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
jsonPayload = jsonPayload & _
"""PartNumberOrMessage"":""" & pPN.Value & """," & _
"""Revision"":""" & pRev.Value & """," & _
"""PartDesc"":""" & pDesc.Value.Replace(ControlChars.Quote, Chr(92) & Chr(34)) & """," & _
"""MakeBuy"":""" & pMB.Value & """," & _
"""Length"":""" & pLength.Value & """," & _
"""Width"":""" & pWidth.Value & """," & _
"""Thick"":""" & pThick.Value & """," & _
"""MtlNum"":""" & pMatNum.Value & """," & _
"""MtlDesc"":""" & pMatDesc.Value & """," & _
"""OP1"":""" & Parameter("OP1") & """," & _
"""OP2"":""" & Parameter("OP2") & """," & _
"""OP3"":""" & Parameter("OP3") & """," & _
"""OP4"":""" & Parameter("OP4") & """," & _
"""Message"":""" & MsgComp & """" & _
"}"
PostLog (jsonPayload)
' My.Computer.Audio.Play("https://froods.ca/~dschaub/AppleSounds/Startup/StartupMacQuadraAV.wav")
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
Sub PostLog(jsonPayload as String)
'MsgBox(jsonPayload)
dim logUrl as String = "https://script.google.com/macros/s/AKfycbxZkgd0ticjJU_XpK5WBDxoJyDmmjRqS0Yfe2Nrmxls0HFoIpbvNprUQ9ChRAb07FGV/exec"
Try
Dim wc As New System.Net.WebClient
wc.Headers.Add("Content-Type", "application/json")
wc.UploadString(logUrl, "POST", jsonPayload)
Catch ex As Exception
'MessageBox.Show("Log failed: " & ex.Message)
End Try
End Sub 'PostLog