forked from Codered741/iLogic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck Drawing Update Status.iLogicVB
More file actions
237 lines (162 loc) · 6.53 KB
/
Copy pathCheck Drawing Update Status.iLogicVB
File metadata and controls
237 lines (162 loc) · 6.53 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
Imports System
Imports System.IO
Imports System.IO.File
Imports System.Text
Sub Main()
'SharedVariable.RemoveAll()
' Dim usrLatestAck = MessageBox.Show("Please ensure that you have the latest drawings of this assembly. " _
' & vbLf & "Contact #des_inventor for assistance. ", "Latest Drawing Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
' If usrLatestAck = vbCancel Then
' Exit Sub
' End If
Dim oDoc as Document = ThisApplication.ActiveDocument
Dim FileNameMinLong as Integer = 21 'c:/_vaultWIP/Designs/ is 21 characters.
'check if active document is an assembly
If isAsm(oDoc) = False
MsgBox("Please run from an Assembly")
Return
End If
'write to iLogic Log
SharedVariable("LogVar") = "Check Drawing Status"
iLogicVB.RunExternalRule("Write SV to Log.iLogicVB")
Dim lstDrawings as New List(of String)
Dim BOMDocs As New List(of String)
'get list of part numbers from Structured BOM
GetDocsFromBOM(ThisApplication.ActiveDocument, BOMDocs)
Dim oProgressBar as Inventor.ProgressBar
oProgressBar = ThisApplication.CreateProgressBar(False, BOMDocs.Count, "Finding Drawings...")
'Attempt to find a drawing file of the same name as the assembly doc
RefDwgFullFileName = FindDrawingFilePN(oDoc)
oProgressBar.Message = "Checking for drawing of " & oDoc.FullFileName
oProgressBar.UpdateProgress
Dim ModelFileInfo = My.Computer.FileSystem.GetFileInfo(oDoc.FullFileName)
Dim ModelAccTime As DateTime = ModelFileInfo.LastWriteTime
Dim RefFileInfo
Dim RefAccTime As DateTime
If RefDwgFullFileName.Length > FileNameMinLong Then
RefFileInfo = My.Computer.FileSystem.GetFileInfo(RefDwgFullFileName)
RefAccTime = RefFileInfo.LastWriteTime
If DateTime.Compare(RefAccTime, ModelAccTime) < 0 Then
lstDrawings.Add(RefDwgFullFileName)
End If
End If
'Dim bDoc as Document
For Each BOMDoc as String In BOMDocs
bDoc = ThisApplication.Documents.ItemByName(BOMDoc) 'convert full file name to document object
oProgressBar.Message = "Checking for drawing of " & BOMDoc 'oRefDoc.FullFileName
oProgressBar.UpdateProgress
'Attempt to find a drawing file of the same name as the model doc
RefDwgFullFileName = FindDrawingFilePN(bDoc)
ModelFileInfo = My.Computer.FileSystem.GetFileInfo(BOMDoc)
ModelAccTime = ModelFileInfo.LastWriteTime
If RefDwgFullFileName.Length > FileNameMinLong Then
RefFileInfo = My.Computer.FileSystem.GetFileInfo(RefDwgFullFileName)
RefAccTime = RefFileInfo.LastWriteTime
If DateTime.Compare (RefAccTime, ModelAccTime) < 0 Then
lstDrawings.Add(RefDwgFullFileName)
End If
End If
Next
oProgressBar.Close
Try
SVal = SharedVariable("BatchPlotInvoke")
Catch
SharedVariable("BatchPlotInvoke") = False
End Try
If lstDrawings.Count > 0 Then
If SharedVariable("BatchPlotInvoke") = False
usrOpenDwgs = MessageBox.Show(lstDrawings.Count & " drawings were found that appear to be out of date. Would you like to open them?", "Drawing Update Check", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Else
MessageBox.Show(lstDrawings.Count & " drawings were found that appear to be out of date. ", "Drawing Update Check", MessageBoxButtons.OK, MessageBoxIcon.Question)
usrOpenDwgs = vbNo
End If
If usrOpenDwgs = vbYes Then
Dim oOptions as NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
oOptions.Value("DeferUpdates") = False
oOptions.Value("FastOpen") = False
For Each Dwg in lstDrawings
ThisApplication.Documents.OpenWithOptions(Dwg, oOptions, True)
Next
End If
Else
MessageBox.Show("No Drawings were found to be out of date. Congrats!!!", "Drawing Update Check", MessageBoxButtons.OK)
End If
End Sub 'Main
Sub GetDocsFromBOM(oDoc as Document, ByRef BOMDocs as List(of String))
If oDoc.DocumentType <> kAssemblyDocumentObject Then
MsgBox("This rule can only be run from an assembly")
Exit Sub
End If
Dim oDocBOM As BOM = oDoc.ComponentDefinition.BOM
oDocBOM.StructuredViewEnabled = True
oDocBOM.StructuredViewFirstLevelOnly = False
oDocBOM.PartsOnlyViewEnabled = False
Dim oBOMView as BOMView = oDocBOM.BOMViews.Item("Structured")
Dim oBOMRows As BOMRowsEnumerator = oBOMView.BOMRows
'Dim oCompDef As ComponentDefinition
'Dim oPNProp as Inventor.Property
For Each oRow as BOMRow in oBOMRows
GetBOMRowDocFile(oRow, BOMDocs)
Next
'BOMDocs.Sort()
End Sub
Sub GetBOMRowDocFile(oRow as BOMRow, ByRef BOMDocs as List(of String))
Dim oCompDef As ComponentDefinition
'Add the part number of the current row, for parts that have children
oCompDef = oRow.ComponentDefinitions.Item(1)
If oCompDef.Type = 100675072 Then 'exclude Virtual Components
'do nothing
Else
DocName = oCompDef.Document.FullFileName
If Not BOMDocs.Contains(DocName) Then
BOMDocs.Add(DocName)
End If
End If
If Not oRow.ChildRows Is Nothing Then
If Not BOMDocs.Contains(DocName) Then
BOMDocs.Add(DocName)
End If
For Each oChildRow as BOMRow in oRow.ChildRows
GetBOMRowDocFile(oChildRow, BOMDocs)
Next
End If
End Sub
Function FindDrawingFilePN(PartOrAssemblyDoc As Document) As String
Dim fullFilenamePN As String
fullFilenamePN = PartOrAssemblyDoc.fullFilename
' Extract the path from the full filename.
Dim path As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
'path = Left$(fullFilenamePN, InStrRev(fullFilenamePN, "\"))
Dim iProps as PropertySet = PartOrAssemblyDoc.PropertySets.Item("Design Tracking Properties")
Dim pn = iProps.Item("Part Number")
Dim filename As String = pn.Value
' Find if the drawing exists.
Dim drawingFilename As String
drawingFilename = ThisApplication.DesignProjectManager.ResolveFile(path, filename & ".dwg")
' Check the result.
If drawingFilename = "" Then
' Find if the drawing exists.
drawingFilename = ThisApplication.DesignProjectManager.ResolveFile(path, filename & ".idw")
' Return the result.
If drawingFilename <> "" Then
Return drawingFilename
Else
Return ""
End If
Else
' Return the result.
Return drawingFilename
End If
End Function 'FindDrawingFilePNN
Function DocumentFileName(Doc As String) As String
DocumentFileName = Left(Doc, Doc.Length - 4)
'MsgBox(DocumentFileName)
End Function 'DocumentFileName
Function isAsm(ThisDoc As Document) As Boolean
Debug.Print (ThisDoc.DocumentType)
If ThisDoc.DocumentType = kAssemblyDocumentObject Then
isAsm = True
Else
isAsm = False
End If
End Function 'isAsm