Error in selecting silhouettes

Hello experts,

    I'm trying to select the below shown Silhouette (Highlighted in Orange) via API, it is a tube component and the drawing view is currently in top view.

I'm try to use below code to achieve it. But unfortunately, it is not working. 

Dim selectByRaySheet as Boolean = DrgDoc.Extension.SelectByRay(X / lengthFactor, Y / lengthFactor, -25000, 0, 0, -1, 0.000000001, 46, False, 1, 0)

I found the problem in which some forum threads says that the Silhouettes might not be loaded properly. Then I hovered over the Silhouette manually using my mouse and then used the above code again. Surprisingly, it works. But I can't do this everytime because I'm automating this drawing.

Later, I created the below code as a solution.

Dim vSilhouetteEdges = view.GetVisibleEntities2(Nothing, SolidWorks.Interop.swconst.swViewEntityType_e.swViewEntityType_SilhouetteEdge)
Dim selData As SelectData = DrgDoc.SelectionManager.CreateSelectData
selData.View = view
' Iterate through the silhouette edges (if any)
If vSilhouetteEdges IsNot Nothing Then
      For i = LBound(vSilhouetteEdges) To UBound(vSilhouetteEdges) 
          vSilhouetteEdges(i).select(False, selData) ' Access each silhouette edge
      Next
Else
      Debug.Print("No silhouette edges found in this view.")
End If

Generally what it is doing is, it is getting all the silhouettes in a drawing view as an array. Then it is selecting it one by one. But in case of large assembly drawing, it is taking a lot of time. How can I overcome this issue.

 

TIA for your time and suggestions.