I am trying to create a Loft feature where both profiles and guides are segments in a 3D Sketch, but it does not work. InsertLoftRefSurface2 works fine when I use curve features instead of sketch segments. Moreover, I can create a Loft feature based on sketch segments in the GUI.
The one difference between GUI and API that I see is that when I select sketch segments in the GUI, SW pops up "Selection Manager" and in the debugger I can see that selected objects are of type swSelOBJGROUP (155), while when I call SketchSegment.Select4 the type of selected objects is swSelEXTSKETCHSEGS (24). I can't figure out how to select swSelOBJGROUP from the API.
Here is a simple macro that does not work (run on an empty part) -
Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Sub main() Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Part.SketchManager.Insert3DSketch True Dim skSegment1 As Object Dim skSegment2 As Object Dim selectData As Object Set skSegment1 = Part.SketchManager.CreateLine(-0.029318, 0.027947, 0#, -0.062721, -0.014683, 0#) Set skSegment2 = Part.SketchManager.CreateLine(0.001561, 0.018772, -0#, -0.024723, -0.014771, -0#) Part.SketchManager.Insert3DSketch False Set selectData = Part.SelectionManager.CreateSelectData() selectData.Mark = 1 Part.ClearSelection2 True skSegment1.Select4 True, selectData skSegment2.Select4 True, selectData swApp.SendMsgToUser2 "Selected object type = " & Part.SelectionManager.GetSelectedObjectType3(1, 1), 2, 2 Part.InsertLoftRefSurface2 False, True, False, 1, 0, 0 End Sub
I am on SolidWorks 2023. Any help is appreciated!