How can I store selected features (edges in my case) in an array? I keep getting "error 9, subscript out of range."
'Precondition: Edges are selected
'Post-condition: Edges are stored in an array "swEdge()"
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim longEdgeCount As Long
Dim swEdge() As SldWorks.Edge
Dim swEnt As SldWorks.Entity
Dim Bret As Boolean
Dim i As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
'Zero edge counter, find edge count value,& subtract 1 to match array index
longEdgeCount = 0
longEdgeCount = swSelMgr.GetSelectedObjectCount2(-1) 'Select regardless of marks
MsgBox longEdgeCount
longEdgeCount = longEdgeCount - 1
'Set selectedObjects to objEdge() array
For i = 0 To longEdgeCount
Set swEdge(i) = swSelMgr.GetSelectedObject6(i + 1, -1)
Next
'Check to see if swEdge is populated correctly
swModel.ClearSelection2 True
For i = 0 To longEdgeCount
Set swEnt = swEdge(i)
Bret = swEnt.Select4(True, swSelData): Debug.Assert Bret
Next
End Sub
SolidworksApi macros