1 person found this helpful
The reason you are getting that error is because your array, swEdge, is dynamic, and dynamic arrays by default have no length. You need to use ReDim to specify an array size before you start assigning values to its elements. For example, this will resize the array so that it can hold the number of items selected:
ReDim swEdge(swSelMgr.GetSelectedObjectCount2(-1) - 1)
ReDim resets the entire array. You will need to use ReDim Preserve if you want to preserve existing elements.
But wait! I would not recommend that you use arrays at all. Rather, use the Collection class, which is much easier to work with. When you declare a collection you will need to use the New keyword, as shown below, because a collection is a class, and classes need to be instantiated. Also be sure to reset your collection each time you run your program.
Here is how I would recommend you write this macro:
'Precondition: Edges are selected
'Post-condition: Edges are stored in collection "colEdges"
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim colEdges As New Collection
Dim swEnt As SldWorks.Entity
Dim i As Integer
Set colEdges = Nothing
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)
colEdges.Add swSelMgr.GetSelectedObject6(i, -1)
For i = 1 To colEdges.Count
Set swEnt = colEdges.Item(i)
swEnt.Select4 True, Nothing
Finally, on a semantic note: "features" refer only to items that reside in a FeatureManager tree. Since edges cannot reside there, they are not considered features. Technically, an edge is an topological entity.
I hope this helps.
Thanks. That is exactly what I wanted to do.