<?xml encoding=”UTF-8″>By Xiaodong Liang
I noticed one forum post my colleague Philippe has helped. I think it may help some customers. This question is to traverse the components which display in the section drawing view.
There is not a direct way, but possible with API.
You could either iterate through all occurrences of your top level assembly and see if “DrawingView.DrawingCurves(occurrence)” returns something, if yes the component is part of the view.
Or the other way around, iterate through all the DrawingCurves in the specific view and check “DrawingCurve.ModelGeometry” to see which occurrence this belong to.
The code below is a small demo. It assumes the second view of the sheet is a section view.
Public Sub GetViewComponents()
Dim doc As DrawingDocument
Set doc = ThisApplication.ActiveDocument
Dim sectionView As SectionDrawingView
Set sectionView = doc.ActiveSheet.DrawingViews(2)
Dim docDesc As DocumentDescriptor
Set docDesc = sectionView.ReferencedDocumentDescriptor
Dim asm As AssemblyDocument
Set asm = docDesc.ReferencedDocument
Debug.Print "Occurrences in View: " & sectionView.name
On Error Resume Next
Dim occurrence As ComponentOccurrence
For Each occurrence In asm.ComponentDefinition.Occurrences
Dim curves As DrawingCurvesEnumerator
Set curves = sectionView.DrawingCurves(occurrence)
If Err Then
'DrawingCurves fails if no curves...
Err.Clear
ElseIf curves Is Nothing Or curves.count = 0 Then
'Component not in view...
Else
'Component is in section view
Debug.Print occurrence.name
End If
Next
End Sub

Leave a Reply