Currently my code will select the actual model edges, which makes selecting the attached image 3 selections since it contains a sheet metal bend (tangent edges are hidden in the view) however when the user tries to select that edge, it merges all 3 edges into one selection. I have tried using GetPolylines7 which seemed like it would give the line as one segment how I wanted but it would still select them separately, similar to how GetVisibleEntities2 worked.
Is there any way to select the model edge with a macro the same way the user can?
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim swView As SldWorks.View
Dim swActiveView As SldWorks.View
Dim swSelMgr As SldWorks.SelectionMgr
Dim swEnt As SldWorks.Entity
Dim swEdge As SldWorks.Edge
Dim boolstatus As Boolean
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim i As Integer
Dim currentfeature As SldWorks.Feature
Dim subfeature As SldWorks.Feature
Dim vComponent As Variant
Dim vEntities As Variant
Dim partName As String
Dim swDrawComp As SldWorks.DrawingComponent
Dim swComp As SldWorks.Component2
Dim startPt As Variant
Dim endPt As Variant
Dim swCurve As SldWorks.Curve
Dim dx As Double
Dim dy As Double
Dim swSEdge As SldWorks.SilhouetteEdge
Dim long1 As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
'Checks---------------------------------------------------
If swModel Is Nothing Then
MsgBox "No active document."
Exit Sub
End If
If swModel.GetType <> swDocDRAWING Then
MsgBox "Not a drawing."
Exit Sub
End If
'---------------------------------------------------------
Set swDraw = swModel
Set swSelMgr = swModel.SelectionManager
Set swSheet = swDraw.GetCurrentSheet
Set swView = swDraw.GetFirstView
Set currentfeature = swModel.FirstFeature
'Starting work--------------------------------------------
While Not swView Is Nothing
Debug.Print " " & swView.GetName2 & " [" & swView.Type & "]"
swDraw.ClearSelection2 True
' Returns false if trying to activate the drawing sheet
boolstatus = swDraw.ActivateView(swView.GetName2)
If boolstatus Then
vComponent = swView.GetVisibleDrawingComponents
'find name of part the view is referencing, obsolete in this code
partName = vComponent(0).Name
Debug.Print partName
'vEntities = swView.GetVisibleEntities2(swComp, 1)
vEntities = swView.GetPolylines7(1, "")
For i = 0 To UBound(vEntities) 'iterate through entities in view and select if edges
Set swEnt = vEntities(i)
'Set swSEdge = vEntities(i)
'If TypeOf swEnt Is SldWorks.SilhouetteEdge Then 'SldWorks.Edge
boolstatus = swEnt.Select4(True, Nothing)
'End If
Next
'see if the selections are vertical or horizontal
For i = 1 To swSelMgr.GetSelectedObjectCount
Set swEdge = swSelMgr.GetSelectedObject6(i, -1)
Set swCurve = swEdge.GetCurve
startPt = swCurve.Evaluate(0)
endPt = swCurve.Evaluate(1)
dx = endPt(0) - startPt(0)
dy = endPt(2) - startPt(2)
If Abs(dx) > 0 And Abs(dy) = 0 Then
Debug.Print "Edge " & i & " is horizontal."
ElseIf Abs(dy) > 0 And Abs(dx) = 0 Then
Debug.Print "Edge " & i & " is vertical."
Else
Debug.Print "Edge " & i & " is angled or 3D."
End If
Next
Else
Debug.Assert swSheet.GetName = swView.GetName2
boolstatus = swDraw.ActivateSheet(swView.GetName2)
End If
Debug.Assert boolstatus
Set swView = swView.GetNextView
Wend
End Sub