It appears that at least with my version of SolidWorks (2016 SP5.0), the InsertSplitLineProject function requires that the entities be selected with the SelectByID2 function. I had tried iterating through functions as you can see below and selecting the entity once found. I verified that they highlighted correctly in my view window but the split line function never succeeded with that selection method.
I named my face on my part "That_Face" and used "Sketch4" as my split line to project. I commented out the lines below that select the faces the way I wanted to do it and replaced them with their SelectByID2 counterpart and the split worked as intended.
If someone else can shed more light on this, I would also be interested in a solution after taking a look at this.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swEnt As SldWorks.Entity
Dim swFace2 As SldWorks.Face2
Dim vBodies As Variant
Dim swBody As SldWorks.Body2
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
vBodies = swPart.GetBodies2(swSolidBody, False)
Set swBody = vBodies(0)
Set swFace2 = swBody.GetFirstFace
swModel.Extension.SelectByID2 "Sketch5", "SKETCH", 0, 0, 0, False, 4, Nothing, 0
'swModel.SelectByName 0, "Sketch4"
Do While Not swFace2 Is Nothing
If swModel.GetEntityName(swFace2) = "That_Face" Then
Set swEnt = swFace2
swModel.Extension.SelectByID2 "", "FACE", 4.79295511889791E-03, 7.54999999998063E-03, -1.90909725465572E-02, True, 1, Nothing, 0
Set swFace2 = swFace2.GetNextFace
swModel.InsertSplitLineProject False, False
I was seeing similar behavior Alex, the real question is how to get around hard coding a selection location that is dependent on view orientation (really surprised that the help files religiously use SelectByID2 with hard coded locations). Seems like this could be a good SPR.
I'm going to try using GetClosestPointOn method to find a location that would always select the face that I needed, but man would it be nice just to point directly at the face.
Damnit, I tried to get around it by using a plane to create a split line, but you have to select with the SelectByID2 method to create a plane!!!
WHY SW API ENGINEERS? WHY MUST WE DO IT SUCH A TERRIBLE WAY????!!!!!?????
Ok, so it seems that I got lucky. I can actually manage to accomplish what I need by making sure the selection point is unique to the face that I need. Man its a lot of logic to ensure that but the macro works.
That does seem like a lot of work and it is not intuitive to the programmer. I feel better iterating through a list of faces to find the one I want to select, however it doesn't appear to select it the same way as the selectByID2 method.
If there was a way to get the X, Y, and Z coordinates of a spot on the face and then use those in the selectByID2 function to select the face then that would be how I would try to approach it next. Unfortunately, I don't have the time right now to sit down and figure out how to determine if a point is on a face and all that. I'm not even sure if that is possible or even if it would work.
Good luck in fine tuning your macro.