- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to write this code to check if parts in an assembly have a drawing associated with them.
It does a pretty good job of identifying parts that do not have drawings.
Currently the code runs and will end with no message boxes if there are no parts missing drawings, however I would like the code to have a "Finished" message once it has run completely through.
My problem is that when there is a subassembly any messagebox will be displayed multiple times if I just put the show messagebox at the end, which can be confusing. Is there a way to work through the parts in the suboccurance and still have a messagebox show saying when the code is done running through the main assembly?
Additionally, The current set up displays a separate messagebox with missing drawings for each subassembly. Is there a way i can group all the missing drawings from each sub and the main assembly into one messagebox at the end?
Thanks
Private Sub Main()
Dim asmDoc As AssemblyDocument
asmDoc = ThisDoc.Document
' Call the function that traverses the assembly
Call Iterate(asmDoc.ComponentDefinition.Occurrences,1)
' Update the view.
ThisApplication.ActiveView.Update
End Sub
Sub Iterate(Occurrences As ComponentOccurrences, Level As Integer)
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisDoc.Document.ComponentDefinition
Dim oPart As ComponentOccurrence
Dim oPartpath As String
Dim needsdwg As New ArrayList
Dim FNamePos As Long
Dim Part_Name As String
'''Iterate through part occurrences in assembly
For Each oPart In Occurrences
Dim oFileName As String = oPart.Definition.Document.FullFileName
'Check to see if occurance is a Part
Dim partnumber As String = iProperties.Value(oPart.Name, "Project", "Part Number")
If oPart.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oDoc As PartDocument = oPart.Definition.Document
If iProperties.Value(oPart.Name, "Custom", "ITS_DTL") = "Y" Then
FNamePos = InStrRev(oFileName, "\", -1)
Part_Name = Right(oFileName, Len(oFileName) -FNamePos)
oPartpath = Left(oFileName, Len(oFileName) -Len(Part_Name))
'sets full file name to search for, drawing must be in same folder as part.
Dim Dwgname As String = oPartpath & "\" & partnumber & ".idw"
'check to see if drawing file exists
If System.IO.File.Exists(Dwgname) = True Then
Else
'Adds part names without a detail to list
needsdwg.Add(partnumber)
End If
Else
End If
'ignore bolted assemblies.
ElseIf partnumber.Contains("Bolted")=True Then
GoTo line1
'recursively call sub to traverse through occurance if it is a subassembly
ElseIf oPart.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Call Iterate(oPart.SubOccurrences, Level)
End If
line1 :
Next
Dim i As Integer
Dim a As Integer
i = needsdwg.Count - 1
Dim partlist(i) As String
For a=0 To i
'moves all items in arraylist to string array.
partlist(a) = needsdwg.Item(CStr(a))
Next
If i = -1 Then
Else
'displays all parts that are missing drawings.
MessageBox.Show("Drawings needed for " & Join (partlist, ", "))
End If
End Sub
Solved! Go to Solution.