Hi all,
Here is the VB code. I have test it successful in SolidWorks VBA. but ,when I copy it in VB.net,it failed.
So I try to change "Dim obj() As Object" to "Dim obj() As Face2", it is OK when I select some faces in SolidWorks Part document.
But in practice, I can't change it to "face2". becuase, I don't know what type entity will be selected(it may faces/sketch/solid/edge......,even their combination).
What should I do now?
thank you very much!
===========================================================================================
Sub main()
Dim swAppp As SldWorks.SldWorks
Dim Doc As SldWorks.ModelDoc2
Dim SelMgr As SelectionMgr
Set swApp = Application.SldWorks
Set Doc = swApp.ActiveDoc
Set SelMgr = Doc.SelectionManager
If SelMgr.GetSelectedObjectCount = 0 Then Debug.Print "No selections found.": Exit Sub
'Put the Selected object in an array
Dim i As Integer
Dim obj() As Object
ReDim obj(SelMgr.GetSelectedObjectCount - 1)
For i = 1 To SelMgr.GetSelectedObjectCount
Set obj(i - 1) = SelMgr.GetSelectedObject6(i, -1)
Next i
Doc.ClearSelection
'MultiSelect the object in "obj" array
Dim seldata As SelectData
Set seldata = Nothing
Dim boolstatus As Boolean
boolstatus = Doc.Extension.MultiSelect(obj, True, seldata) 'This code doesn't work in VB.Net
End Sub
===========================================================================================
You could use Entity instead of Object. That supports faces, edges and vertices.
You could use SelMgr.GetSelectedObjectType3 to determine if the selected item is one of those types. If not, don't add it to the obj array.
In .Net, I would use a list rather than an array. That way you don't need to know how many objects you will be adding - you just add them one at a time if they are a face, edge or vertex.
Dim swEntities As New List(Of Entity)
For i = 1 To SelMgr.GetSelectedObjectCount
If SelMgr.GetSelectedObjectType3(i, -1) = swSelectType_e.swSelFaces Then
swEntities.Add(SelMgr.GetSelectedObject6(i, -1))
End If
Next i
...
boolstatus = Doc.Extension.MultiSelect2(swEntities.ToArray, True, seldata)