Anonymous
in reply to:
Anonymous
10-20-2016
10:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-20-2016
10:04 PM
Here is a version which does some error checking (previous version could throw an error) and is a bit faster. It also prints the output into a text file.
Dim appearanceToFind As String = "Axe grip"
'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
'Create a dictionary which will be used to store the appearances
Dim Appearances As Object
Appearances = CreateObject("Scripting.Dictionary")
'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments
'format file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
'Get the part face
Dim oFaces As Faces
'Only look at part files
If docFile.DocumentType = kPartDocumentObject Then
Try
oFaces = docFile.ComponentDefinition.SurfaceBodies(1).Faces
Catch ex As Exception
End Try
End If
'Loop through each face and store the part in the dictionary if the appearance matches
Dim oFace As Face
For Each oFace In oFaces
If appearanceToFind = oFace.Appearance.DisplayName Then
Appearances(docFName) = Appearances(docFName)
Exit For
End If
Next
Next
Dim partList As String
'Gather the contents of the dictionary
For Each Item In Appearances
partList += Item + vbCrLf
Next
'MessageBox.Show("Parts found with appearance " & appearanceToFind & ":" & vbLf & partList)
oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & " parts with appearance" & ".txt")
oWrite.WriteLine(partList)
oWrite.Close()