Let’s suppose we should select all the hole features on the drawing view that are orthogonal to the view plane.
In other words, for every hole feature that is projected on the drawing view we should check its orientation and if this hole is orthogonal to the drawing view plane we should add all its drawing curve segments to the DrawingDocument.SelectSet collection.
The part model used here has two non-parallel hole features.
There is a pair of places in the code that are worth noting.
1) DrawingView API provides the magic property that returns all the drawing curves within my drawing view filtered to the input model object. Here the HoleFeature objects were used.
DrawingView.DrawingCurves( [ModelObject] As Variant ) As DrawingCurvesEnumerator
2) How we can check if the hole is orthogonal to the view plane or not? I did it comparing two vectors. One vector is defined by the view camera orientation. It could be created by two points – Eye and Target. Calculations of the second vector depend on the hole placement definition. Here I used the normal to the sketch where the center points were created. Vector.IsParallelTo() method gives the answer if these two vectors are parallel or not. If they are parallel all drawing curve segments projected from this hole feature should be added to the SelectSet collection.
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
'active drawing doc
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
'the 1st drawing view
Dim oView As DrawingView
Set oView = oSheet.DrawingViews.Item(1)
Dim oCamera As Camera
Set oCamera = oView.Camera
Dim oEye As Point, oTarget As Point
Set oEye = oCamera.Eye
Set oTarget = oCamera.Target
Dim oVec As Vector
Set oVec = oTG.CreateVector( _
oEye.x - oTarget.x, _
oEye.y - oTarget.y, _
oEye.z - oTarget.z)
Dim oSSet As SelectSet
Set oSSet = oDrawDoc.SelectSet
'model document, need to find hole features
Dim oDoc As PartDocument
Set oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oDef As PartComponentDefinition
Set oDef = oDoc.ComponentDefinition
Dim oHoleFeatures As HoleFeatures
Set oHoleFeatures = oDef.Features.HoleFeatures
'collection for segments to be selected
Dim oColl As ObjectCollection
Set oColl = ThisApplication.TransientObjects.CreateObjectCollection
Dim oHole As HoleFeature
For Each oHole In oHoleFeatures
Dim oCurves As DrawingCurvesEnumerator
Set oCurves = oView.DrawingCurves(oHole)
Debug.Print oHole.name, oCurves.Count
If oCurves.Count > 0 Then
'this hole feature is seen in the drawing view
'so we need to check the hole orientation.
'Method depends on the hole placement definition !
Dim oSketch As PlanarSketch
Set oSketch = oHole.PlacementDefinition.HoleCenterPoints.Item(1).Parent
Dim oNormal As UnitVector
Set oNormal = oSketch.PlanarEntity.Geometry.normal
If oVec.IsParallelTo(oNormal.AsVector, 0.0000001) Then
Debug.Print "Hole is orthogonal"
'populate the collection to select segments later
Dim oCurve As DrawingCurve
Dim dcs As DrawingCurveSegment
For Each oCurve In oCurves
For Each dcs In oCurve.Segments
Debug.Print "Hole is slanted" 'do nothing
'select drawing curve segments found
If oColl.Count > 0 Then
MsgBox "Done :)"
MsgBox "No orthogonal holes found"
Output to the Immediate Window:
Hole is slanted
Hole is orthogonal