6 Replies Latest reply on Aug 17, 2017 9:31 AM by Alex Burnett

    Projected Split Line API

    Swme Eng

      I am working on a macro to split a face, and read through the documentation on the InsertSplitLineProject method. It says that you have to use SelectByID2 with certain marks to actually get the split line to work. I know that selecting faces with the SelectByID2 method is a PITA, is there another way to add marks and still get InsertSplitLineProject to work?

        • Re: Projected Split Line API
          Alex Burnett

          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
          Sub main()
          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.ClearSelection2 True
          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
                  'swEnt.Select (True)
              End If
              Set swFace2 = swFace2.GetNextFace
          Loop
          swModel.InsertSplitLineProject False, False
          End Sub
            • Re: Projected Split Line API
              Swme Eng

              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.

              • Re: Projected Split Line API
                Swme Eng

                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????!!!!!?????

                • Re: Projected Split Line API
                  Swme Eng

                  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.

                    • Re: Projected Split Line API
                      Alex Burnett

                      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.