02-15-2017
10:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
02-15-2017
10:02 PM
Yea, it's iLogic. Also there should be "Sheet" instead of "DrawingSheet".
Sub Main
'Get the active document
Dim oDoc As Document = ThisApplication.ActiveDocument
'Check if it's a drawing
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
'Get the drawing sheets
Dim oSheets As Sheets = oDoc.Sheets
'Get the top/sub doc from 1./2. sheet, 1. view
Dim oTopDoc As Document = GetViewDoc(oSheets, 1, 1)
Dim oSubDoc As Document = GetViewDoc(oSheets, 2, 1)
If oTopDoc Is Nothing Or oSubDoc Is Nothing Then Exit Sub
Dim oTopCD As AssemblyComponentDefinition = oTopDoc.ComponentDefinition Dim oPartEnum As ComponentOccurrencesEnumerator = oTopCD.Occurrences.AllReferencedOccurrences(oSubDoc) Dim QTY As Integer = oPartEnum.Count
MsgBox(QTY)
End Sub
Private Function GetViewDoc(oSheets As Sheets, iSheet As Integer, iView As Integer) As Document
Dim oDoc As Document = Nothing
Try
Dim oSheet As Sheet = oSheets(iSheet)
Dim oView As DrawingView = oSheet.DrawingViews(iView)
oDoc = oView.ReferencedFile.ReferencedDocument
Catch
End Try
Return oDoc
End Function
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods