-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCreate Structure.iLogicVB
More file actions
469 lines (350 loc) · 16.1 KB
/
Create Structure.iLogicVB
File metadata and controls
469 lines (350 loc) · 16.1 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
'TAIT Showfile Structure Creator
'Purpose:
' To maintain consistency in show data management, this rule will create folder structure in the Showfile and store this folder path in an iProperty for future use. It will also create an assembly, pre-configured with the correct Element/Kit information, and insert it into the current Show/Element assembly.
' In Creating a show, the rule will create a show folder, named "SHOW NAME XXXX - 12X3456", with a show assembly inside.
'The show assembly will be named the Job number, XXXXXX.iam, with the description "MASTER ASSEMBLY"
' For Shows, the rule will create a Show Assembly,
' For Elements, the rule will create kits
' For kits, the rule will error.
Imports System.IO
Imports System.IO.Path
Imports System.Text
Imports System.Collections
Imports System.Windows.Forms
Imports My.Computer.FileSystem
Sub Main()
'On Error Resume Next
SharedVariable("LogVar") = "Create Structure"
iLogicVb.RunExternalRule("Write SV to Log.iLogicVB")
'read in the path to the templates and test that it Exists
dim strTemplatesPath as String = "C:\_vaultWIP\Designs\Templates\" 'getTemplatesFolderPath()
'messagebox.show(strTemplatesPath)
If strTemplatesPath.Length = 0 Then
MessageBox.Show("Error getting the path to the Templates location. Exiting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End if
If Not ThisApplication.ActiveEditDocument Is ThisApplication.ActiveDocument Then
MessageBox.Show("This rule cannot be run from an in-place edit. Please open the file exclusively, and try again. ", "No in-place creation", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim oDoc As Document = ThisApplication.ActiveEditDocument
Dim oCustProps As Inventor.PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
'check if document is assembly
If oDoc.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run from an assembly. ")
Exit Sub
End If
usrContinue = MessageBox.Show("This will create a new Show/Element/Kit assembly and corresponding folder structure. Are you sure you are ready to continue? ", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If Not usrContinue = vbOK Then
MsgBox("Canceling")
Exit Sub
End If
Dim pDL As Inventor.Property
Try
'get DesignLevel Prop
pDL = oCustProps.Item("DesignLevel")
'catch non-existant property
Catch
'add DesignLevel property
oCustProps.Add("", "DesignLevel")
pDL = oCustProps.Item("DesignLevel")
Err.Clear
End Try
Try
temp = oCustProps.Item("AutoStruct").Value
Catch
fix = MessageBox.Show("This assembly was not created with the correct rule. If you have correctly completed 'Epicor Job Config', you can correct this now by selecting 'Yes'. " & _
vbCr & "Are you sure Epicor Job Config is Correct?", "Auto Assembly Failure", MessageBoxButtons.YesNo, MessageBoxIcon.Error)
If fix = vbYes Then
oCustProps.Add(True, "AutoStruct")
Else
MsgBox("Exiting")
Exit Sub
End if
End Try
'handle shows and elements differently, if not configured, create show.
If pDL.Value = "Show" 'create Elements
If oCustProps.Item("AutoStruct").Value = True Then
CreateElement(oDoc, strTemplatesPath)
End If
Else If pDL.Value = "Element" Then 'Create Kits
If temp = oCustProps.Item("AutoStruct").Value = True Then
CreateKit(oDoc, strTemplatesPath)
End If
Else If pDL.Value = "Kit" Then
MessageBox.Show("Element/Kit creation can only be done from configured Show/Element Assembly. Please check your Config, or open a Show/Element. ", "Show/Element Only", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
usrCreateShow = MessageBox.Show("Do you want to create a show?", "Create Show?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If usrCreateShow = vbYes Then
'show create Subroutine
CreateShow(strTemplatesPath)
Else
MsgBox("Nothing left to do!" & vbLf & "¯\_(ツ)_/¯")
Exit Sub
End If
End If
If Err.Number <> 0 Then
MsgBox("An error occurred. The rule may not have run completely. " & Err.Number & " - " & Err.Description)
End If
End Sub
'SUBROUTINES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Sub CreateShow(strTemplatesPath as String)
'get showfile folder - GetShowFilePath Subroutine
'Dim sfPath as String = GetShowFilePath 'Remove references to Show File
showNum:
'get job number from user = JOBNUMBER
Dim ShowNumber As String = InputBox("Please enter the Base 6 digit Epicor Job Number. " & vbLf & "e.g. 123456", "Job Number", "XXXXXX")
If ShowNumber = "" Then
MsgBox("Canceling")
Exit Sub
Else If Not ShowNumber.Length = 6 Then
MessageBox.Show("The Show Number must be 6 digits. ", "Show Number Length", MessageBoxButtons.OK)
GoTo showNum
End If
If Not Int32.TryParse(ShowNumber, 000000) Then 'ShowNumber.Length = 6 Then
MsgBox("The Show Number must be an integer. ")
GoTo showNum
End If
'create folder in WIP
'$\PROJECTNAME - PROJECTNUMBER
Dim ShowName As String = InputBox("Please enter the show name. ", "Show Name", "").ToUpper
Dim pID As String = InputBox("Please enter the Epicor project ID " & vbLF & "e.g. 12X3456", "Project ID", "").ToUpper
'dim ShowDir = "C:\_vaultWIP\Designs\" & ParsePrjName(sfPath) '"C:\_vaultWIP\Designs\CHICAGO LYRIC OPERA 2020 RNTLS - 20A0008"
Dim ShowDir = "C:\_vaultWIP\Designs\" & ShowName & " - " & pID
If System.IO.File.Exists(ShowDir & "\" & ShowNumber & ".iam") Then
MsgBox("An assembly with this name already exists in your WIP for this show. Please check to see if the show has already been created. ")
Exit Sub
Else
Directory.CreateDirectory(ShowDir)
End If
'create new assembly
Dim oShowAsm As AssemblyDocument = ThisApplication.Documents.Add(kAssemblyDocumentObject, strTemplatesPath + "TT_Kit.iam", True)
oShowAsm.Activate()
'save in project folder = JOBNUMBER.iam
oShowAsm.SaveAs(ShowDir & "\" & ShowNumber & ".iam", False)
'oShowAsm.ComponentDefinition.Occurrences.Item(1).Delete 'This line deleted the banana in the kit .iam template
'part number = job number
'done automatically as a part of save
'fill properties
SetProps(oShowAsm, ShowName, ShowName, "" , ShowNumber, "", "Show")
oShowAsm.Update
oShowAsm.Save
SetUnits(oShowAsm)
MessageBox.Show("The Show was created successfully. " & vbLf & ShowNumber & vbLf & ShowName & vbLf & pID , "Show Created", MessageBoxButtons.OK)
End Sub 'CreateShow
Sub CreateElement(doc As AssemblyDocument, strTemplatesPath as String)
'get element project
elementProj = doc.PropertySets.Item("Design Tracking Properties").Item("Project").Value
Dim oPath As String = ThisDoc.Path
'Prompt user for element number and description
eDesc:
Dim elementDesc As String = InputBox("Enter Element Description Only - No extra dashes or spaces", "Element Description", "").ToUpper
' If elementDesc - "" Then
' Return
' End If
If elementDesc.Length > 37 OrElse elementDesc.Length < 2 Then
MsgBox("Description must be between 2 and 37 characters. Try again")
GoTo eDesc
End If
eNumber:
Dim elementNum As String = InputBox("Enter Element Number Only - No extra dashes or spaces. 2-3 digits. ", "Element Number", "XXX")
If elementNum = "" Then
MsgBox("Canceling")
Exit Sub
Else If Not elementNum.Length <4 Then
MessageBox.Show("Element Number must be three digits or less. Try Again. ", "Element Number Length", MessageBoxButtons.OK)
GoTo eNumber
End If
If Not Int32.TryParse(elementNum, 00) Then
MsgBox("Element Number must be an integer. Try Again. ")
Err.Clear
GoTo eNumber
End If
'get show Level number
showNum = doc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
elementNum = showNum & "-" & elementNum
Dim ElementDir As String = oPath & "\" & elementNum & " - " & elementDesc & "\"
'Dim ElementDir As String = "C:\_vaultWIP\Designs\" & elementProj & "\" & elementNum & " - " & elementDesc & "\"
If Directory.Exists(ElementDir) Then
MsgBox("A folder already exists in your WIP for this element. Please check to see if the element has already been created. ")
Exit Sub
Else
Directory.CreateDirectory(ElementDir)
'FileIO.FileSystem.CreateDirectory(ElementDir)
End If
Dim oElementAsm As AssemblyDocument = ThisApplication.Documents.Add(kAssemblyDocumentObject, strTemplatesPath + "TT_Kit.iam", True)
'oElementAsm.SaveAs("C:\_vaultWIP\Designs\" & ShowDir & "\" & elementNum & ".iam", False)
oElementAsm.SaveAs(oPath & "\" & elementNum & ".iam", False)
'oElementAsm.ComponentDefinition.Occurrences.Item(1).Delete 'This line deleted the banana in the kit .iam template
'Write properties to element
SetProps(oElementAsm, elementProj, elementDesc, "", elementNum, "Element Overview", "Element")
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oMatrix As Matrix = oTG.CreateMatrix
doc.Activate()
Dim oElementOcc As ComponentOccurrence = doc.ComponentDefinition.Occurrences.Add(oElementAsm.FullFileName, oMatrix)
oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0))
oElementOcc.Grounded = True
oElementAsm.DisplayName = elementNum & " - " & elementDesc.ToUpper
oElementAsm.Update
SetUnits(oElementAsm)
oElementAsm.Save
oElementAsm.Close
doc.save
MessageBox.Show("The Element was created successfully. " & vbLf & elementNum & "-" & elementDesc.ToUpper, "Element Created", MessageBoxButtons.OK)
End Sub 'CreateElement
Sub CreateKit(doc As AssemblyDocument, strTemplatesPath As string)
'create kit assembly
'file number is element job number concatenated with user entered kit number, and saved into the same directory as element
'new assembly to be inserted at origin of the element assembly, and grounded.
'exportPath property is copied from element, concatenate \SUB ASSEMBLIES\'kitnumber' - 'KIT DESCRIPTION'\
'get kit project from element
kitProj = doc.PropertySets.Item("Design Tracking Properties").Item("Project").Value
'get element number from element assembly
eleNum = doc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
'get element description from element assembly
eleDesc = doc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
'get element path from assembly
'eleExportPath = doc.PropertySets.Item("Inventor User Defined Properties").Item("exportPath").Value
'Prompt user for kit number and description
kDesc:
Dim kitDesc As String = InputBox("Enter Kit Description - No extra dashes or spaces", "Kit Description", "").ToUpper
' If kitDesc - "" Then
' Return
' End If
If kitDesc.Length > 37 OrElse kitDesc.Length < 3 Then
MsgBox("Description must be between 3 and 37 characters. Try again")
GoTo kDesc
End If
kNumber:
Dim kitNum As String = InputBox("Enter Kit Number - No extra dashes or spaces. 2-3 digits. ", "Kit Number", "XXX")
If kitNum = "" Then
MsgBox("Canceling")
Exit Sub
Else If Not kitNum.Length < 4 Then
MessageBox.Show("Kit Number too long. Try Again. ", "Kit Number Length", MessageBoxButtons.OK)
GoTo kNumber
End If
If Not Int32.TryParse(kitNum, 00) Then
MsgBox("Kit Number must be an integer. Try Again. ")
Err.Clear
GoTo kNumber
End If
'get show Level number
showNum = doc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
kitNum = showNum & "-" & kitNum
Dim oPath As String = ThisDoc.Path
Dim kitDir = Left(doc.FullFileName, InStrRev(doc.FullFileName, "\"))
Dim okitAsm As AssemblyDocument = ThisApplication.Documents.Add(kAssemblyDocumentObject, strTemplatesPath + "TT_Kit.iam", True)
okitAsm.SaveAs(oPath & "\" & eleNum & " - " & eleDesc & "\" & kitNum & ".iam", False)
'okitAsm.ComponentDefinition.Occurrences.Item(1).Delete 'This line deleted the banana in the kit .iam template
'Write properties to kit
SetProps(okitAsm, kitProj, kitDesc, eleExportPath & "SUB ASSEMBLIES\" & kitNum & "-" & kitDesc.ToUpper & "\", kitNum, eleDesc, "Kit")
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oMatrix As Matrix = oTG.CreateMatrix
doc.Activate()
Dim okitOcc As ComponentOccurrence = doc.ComponentDefinition.Occurrences.Add(okitAsm.FullFileName, oMatrix)
oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0))
okitOcc.Grounded = True
okitAsm.DisplayName = kitNum & " - " & kitDesc.ToUpper
okitAsm.Update
SetUnits(okitAsm)
okitAsm.Save
okitAsm.Close
doc.save
MessageBox.Show("The Kit was created successfully. " & vbLf & kitNum & "-" & kitDesc.ToUpper, "Kit Created", MessageBoxButtons.OK)
End Sub 'CreateKit
Private Sub SetProps(oAsm As AssemblyDocument, Project As String, Description As String, ePath As String, JobNumber As String, ElementDesc As String, DesignLevel As String)
Dim oShowCustProps As PropertySet = oAsm.PropertySets.Item("Inventor User Defined Properties")
Dim oShowDesProps As PropertySet = oAsm.PropertySets.Item("Design Tracking Properties")
Dim oShowSumProps As PropertySet = oAsm.PropertySets.Item("Inventor Summary Information")
'part number = job number
'done automatically as a part of save
'Project Name = FolderName
oShowDesProps.Item("Project").Value = Project
'description = "Master Assembly"
oShowDesProps.Item("Description").Value = Description
'set creation date to Now
'oShowDesProps.Item("Creation Time").Value = DateString
' set automatically on first save
'set Designer to current user
oShowDesProps.Item("Designer").Value = ThisApplication.UserName.Replace(".", " ")
'Set revision to "0"
oShowSumProps.Item("Revision Number").Value = "0"
'store path to "exportPath" iprop
' oShowCustProps.Add(ePath, "exportPath")
' If Directory.Exists(oShowCustProps.Item("exportPath").Value) = False Then
' Directory.CreateDirectory(oShowCustProps.Item("exportPath").Value)
' End If
'Run Kit Epicor Config Rule (set job number)
oShowCustProps.Item("JobNum").Value = JobNumber
'element name = ""
oShowCustProps.Item("Element_Desc").Value = ElementDesc
oShowCustProps.Item("DesignLevel").Value = DesignLevel
oAsm.ComponentDefinition.Parameters.UserParameters.Item("DesignLevel").Value = DesignLevel
Try
prop = oShowCustProps.Item("AutoStruct")
Catch
oShowCustProps.Add(True, "AutoStruct")
End Try
oShowCustProps.Item("AutoStruct").Value = True
End Sub
'FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Function GetShowFilePath() As String
' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()
' Set options for folder browser dialog
Dialog.SelectedPath = "R:\"
Dialog.ShowNewFolderButton = False
Dialog.Description = "Choose Folder"
' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
' User clicked 'ok' on dialog box - capture the export path
Return Dialog.SelectedPath & "\"
Else
' User clicked 'cancel' on dialog box - exit
Return ""
End If
End Function 'GetShowFilePath
Function ParsePrjName(folder As String) As String
' Dim test As Integer = folder.Length - InStr(folder, "-")
' Dim numLen as Integer = 0
' Dim FolderLen as Integer = folder.Length
' Dim NameLen as Integer
' If test = 11 Then
' numLen = 12
' Else If test = 9 Then
' numLen = 10
' Else
' Return ""
' End If
' NameLen = FolderLen - NumLen
' Return Right(Left(folder, NameLen), Left(folder, NameLen).Length - 3)
Prj = Right(folder, folder.Length -3)
Return Left(Prj, Prj.Length - 1)
End Function 'ParsePrjName
Function getTemplatesFolderPath () as string
Dim invTempLoc as String = "C:\_vaultWIP\inv_Templates_Path.txt"
If System.IO.File.Exists(invTempLoc)
Dim oRead as new StreamReader(invTempLoc)
Try
return oRead.ReadLine()
oRead.Close()
Catch
return 0
End Try
Else
'MessageBox.Show("The template path reference could not be found. ","File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error)
return 0
End if
End Function
Sub SetUnits(doc as Document)
bool = InputRadioBox("Select Units", "Imperial", "Metric", True, Title := "Units Selection")
oUOM = doc.UnitsOfMeasure'.MassUnits = 11283
If bool = False Then 'Set Metric Units
oUOM.MassUnits = 11283 'UnitsTypeEnum.kKilogramMassUnits
oUOM.LengthUnits = 11269 'UnitsTypeEnum.kMillimeterLengthUnits
Else
oUOM.MassUnits = 11286 'UnitsTypeEnum.kLbMassMassUnits
oUOM.LengthUnits = 11272 'UnitsTypeEnum.kInchLengthUnits
End If
End Sub 'SetUnits