What I want to add is to be able to select the two surface bodies that are at the same locations of the originally selected faces, knit them together, then select the body that is created and body keep/delete (keep) it. I do not have a lot of coding experience so I attempted to use swModelDocExt.SelectByID2 but this would not consistently select the same faces that I originally had selected.
Any help is appreciated, thanks!
Prereq: select two faces of a solid body
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Dim swPart As SldWorks.PartDoc
Dim swBody As SldWorks.Body2
Dim swFace As SldWorks.Face2
Dim swFaceRef As SldWorks.Face2
Dim swObj() As Object
Dim swRef() As Variant
Dim intArraySize As Integer
Dim i As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set SelMgr = swModel.SelectionManager
Set swPart = swModel
tol = 0.00001
If SelMgr.GetSelectedObjectCount2(-1) <> 2 Then
MsgBox "Select exactly two faces. The first cannot fully contain any feature, i.e. a hole."
Exit Sub
End If
Set swFaceRef = SelMgr.GetSelectedObject6(1, -1)
swFaceNormal = swFaceRef.Normal
'Get persistent IDs of selected objects
intArraySize = SelMgr.GetSelectedObjectCount2(-1) - 1
ReDim swObj(intArraySize) As Object
ReDim swRef(intArraySize) As Variant
For i = 0 To intArraySize
Set swObj(i) = SelMgr.GetSelectedObject6(i + 1, -1)
swRef(i) = swModel.Extension.GetPersistReference3(swObj(i))
Next i
'------
swModel.ClearSelection2 True
SetSurf (0)
swModel.InsertOffsetSurface 0#, False
SetSurf (0)
swModel.InsertDeleteFace
'------
End Sub
Function SetSurf(i)
Set swObj(i) = swModel.Extension.GetObjectByPersistReference3(swRef(i), Empty)
swObj(i).Select2 True, Empty
End Function