forked from Codered741/iLogic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate Structure.iLogicVB
More file actions
379 lines (288 loc) · 13.4 KB
/
Create Structure.iLogicVB
File metadata and controls
379 lines (288 loc) · 13.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
'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.
' For Shows, the rule will create elements
' For Elements, the rule will create kits
' For kits, the rule will error.
Imports System.IO
Imports System.IO.Path
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")
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
'get DesignLevel Prop
Dim pDL as Inventor.Property
pDL = oCustProps.Item("DesignLevel")
'catch non-existant property
If Err.Number <> 0 Then
'add DesignLevel property
oCustProps.Add("", "DesignLevel")
pDL = oCustProps.Item("DesignLevel")
Err.Clear
End If
'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)
Else
MessageBox.Show("This show was not created with the correct rule. Please contact #des_inventor for assistance", "Not Auto Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Err.Number <> 0 Then
MessageBox.Show("An Error has occurred, please try again. ", "Create Element Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Else If pDL.Value = "Element" Then 'Create Kits
If oCustProps.Item("AutoStruct").Value = True Then
CreateKit(oDoc)
Else
MessageBox.Show("This Element was not created with the correct rule. Please contact #des_inventor for assistance", "Not Auto Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Err.Number <> 0 Then
MessageBox.Show("An Error has occurred, please try again. ", "Create Kit Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
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
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()
'get showfile folder - GetShowFilePath subroutine
Dim sfPath as String = GetShowFilePath
showNum:
'get job number from user = JOBNUMBER
Dim ShowNumber as String = InputBox("Please enter the Base Epicor Job Number. ", "Job Number", "")
If Not Int32.TryParse(ShowNumber, 000000) Then 'ShowNumber.Length = 6 Then
MsgBox("The Show Number must be an integer. ")
Goto showNum
End If
If Not ShowNumber.Length = 6 Then
MsgBox("The Show Number must be 6 digits. ")
Goto showNum
End If
'create folder in WIP
'$\PROJECTNAME - PROJECTNUMBER
dim ShowDir = "C:\_vaultWIP\Designs\" & ParsePrjName(sfPath) '"C:\_vaultWIP\Designs\CHICAGO LYRIC OPERA 2020 RNTLS - 20A0008"
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, "C:\_vaultWIP\Designs\Templates\TT_Kit.iam", True)
oShowAsm.Activate()
'save in project folder = JOBNUMBER.iam
oShowAsm.SaveAs(ShowDir & "\" & ShowNumber & ".iam", False)
oShowAsm.ComponentDefinition.Occurrences.Item(1).Delete
'part number = job number
'done automatically as a part of save
'fill properties
SetProps(oShowAsm, ParsePrjName(sfPath), "MASTER ASSEMBLY", sfPath & "X-REF MASTER FILES\" & ShowNumber & " - INVENTOR MASTER ASSEMBLY\", ShowNumber, "", "Show")
oShowAsm.Update
oShowAsm.Save
MessageBox.Show("The Show was created successfully. " & vbLf & ParsePrjName(sfPath) & vbLf & ShowNumber & "-MASTER ASSEMBLY", "Show Created", MessageBoxButtons.OK)
End Sub 'CreateShow
Sub CreateElement(doc as AssemblyDocument)
'get element project
elementProj = Doc.PropertySets.Item("Design Tracking Properties").Item("Project").Value
'Prompt user for element number and description
eDesc:
Dim elementDesc as String = InputBox("Enter Element Description", "Element Description", "").ToUpper
If elementDesc.Length > 37 OrElse elementDesc.Length < 3 Then
MsgBox("Description must be between 3 and 37 characters. Try again")
GoTo eDesc
End If
eNumber:
Dim elementNum As String = InputBox("Enter Element Number", "Element Number", "")
If Not elementNum.Length = 2 Then
MsgBox("Element Number must be two digits. Try Again. ")
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 = "C:\_vaultWIP\Designs\" & elementProj & "\" & elementNum & "\"
' 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)
' End If
Dim oElementAsm As AssemblyDocument = ThisApplication.Documents.Add(kAssemblyDocumentObject, "C:\_vaultWIP\Designs\Templates\TT_Kit.iam", True)
oElementAsm.SaveAs("C:\_vaultWIP\Designs\" & elementProj & "\" & elementNum & ".iam", False)
oElementAsm.ComponentDefinition.Occurrences.Item(1).Delete
'Write properties to element
SetProps(oElementAsm, elementProj, elementDesc, "R:\" & elementProj & "\X-REF MASTER FILES\" & elementNum & " - " & elementDesc.ToUpper & " - INVENTOR\", 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
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)
'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", "Kit Description", "").ToUpper
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", "Kit Number", "")
If Not kitNum.Length = 2 Then
MsgBox("Kit Number must be two digits. Try Again. ")
Goto kNumber
End If
'num = CInt(kitNum)
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 kitDir = Left(doc.FullFileName, InstrRev(doc.FullFileName, "\"))
Dim okitAsm As AssemblyDocument = ThisApplication.Documents.Add(kAssemblyDocumentObject, "C:\_vaultWIP\Designs\Templates\TT_Kit.iam", True)
okitAsm.SaveAs(kitDir & "\" & eleNum & "\" & kitNum & ".iam", False)
okitAsm.ComponentDefinition.Occurrences.Item(1).Delete
'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
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