3 Replies Latest reply on Jan 29, 2015 11:11 AM by Keith Rice

    Boundary Surface Macro(need help finishing)

    Alex Beaulier

      I was wondering if anyone could help me in finishing this macro. I have built a set of line segments I wish to connect with the boundary surface tool. I have a midpoint of each line in Excel A1-A31, B, and C. A is the x coordinate, B is the y coordinate, and C is the z coordinate for picking the edge for Surface Boundary Connections.

       

      Here is a picture of the Excel with midpoints in the first three columns, and the lines in the SolidWorks Part File.

      BoundaryMacroPicture.png

       

      I feel like I need to do a boolstatus = swModelDocExt.SelectByID2("", EDGE", x31, y31, z31, True, 2, Nothing, 0) at the end of the macro before it reaches the final line segment which is row 31 in my Excel Document. Does anyone see what I could improve or how to finish this?

       

      Here is the macro that I have tried to build.

      Option Explicit

      Dim swApp As SldWorks.SldWorks
      Dim swModel As SldWorks.ModelDoc2
      Dim swSketchMgr As SldWorks.SketchManager
      Dim swExcel As Excel.Application
      Dim exSheet As Excel.Worksheet
      Dim swSelMgr As SldWorks.SelectionMgr
      Dim SwModelDocExt As SldWorks.ModelDocExtension
      Dim swFeatMgr As SldWorks.FeatureManager
      Dim i As Integer
      Dim xpt As Double
      Dim ypt As Double
      Dim zpt As Double
      Dim boolstatus As Boolean

       

      Sub main()

          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swExcel = GetObject(, "Excel.Application")
          Set exSheet = swExcel.ActiveSheet

          swModel.ClearSelection2 True
          Set swSelMgr = swModel.SelectionManager
          Set SwModelDocExt = swModel.Extension
         
         
      i = 1
            Do While exSheet.Cells(i, 1).Value <> ""
           
             
              xpt = exSheet.Cells(i, 1).Value / 1000
              ypt = exSheet.Cells(i, 2).Value / 1000
              zpt = exSheet.Cells(i, 3).Value / 1000
           
              boolstatus = SwModelDocExt.SelectByID2("", "EDGE", xpt, ypt, zpt, False, 1, Nothing, 0)
            
                
      i = i + 1

      Loop

      Set swFeatMgr = swModel.FeatureManager

      swFeatMgr.SetNetBlendCurveData 0, 0, 0, 0, 1, True
      swFeatMgr.SetNetBlendDirectionData 0, 32, 0, False, False
      swFeatMgr.SetNetBlendCurveData 1, 0, 0, 0, 1, True
      swFeatMgr.SetNetBlendDirectionData 1, 32, 0, False, False
      swFeatMgr.InsertNetBlend 2, 1, 1, False, 0.0001, False, True, True, True, False, -1, -1, False, -1, False, False, -1, False, False, True

         
      End Sub

        • Re: Boundary Surface Macro(need help finishing)
          Keith Rice

          Alex,

           

          Interesting project. It is doubtful, however, that anyone here has the time necessary to understand your project at the depth required to help you complete it in such a general sense. My recommendation is that you break down your problem into sub-problems and then post each problem individually.

           

          For example, if your problem is that you aren't able to create a boundary surface from a given sketch, simply post that sketch, note what entities need to be selected, and ask how a boundary surface could be created from it. If you go this route, I would recommend that you edit your original question and change the title rather than simply posting a new question.

           

          See How to ask a good question in the API forum

           

          Hope this helps.

           

          Keith

          SolidWorks API Training

            • Re: Boundary Surface Macro(need help finishing)
              Alex Beaulier

              Would you happen to know if there is a guide on the individual pieces of code such as this part?

               

              boolstatus = SwModelDocExt.SelectByID2("", "EDGE", xpt, ypt, zpt, False, 1, Nothing, 0)

               

              I know the guides post a similar code on the SolidWorks Boundary Surface page, but it would be great if I could learn what the individual numbers in the code mean such as the False, 1, Nothing, 0 are. I don't quite understand where people learn what the individual parts of the code are referring to and I'm still learning API.

                • Re: Boundary Surface Macro(need help finishing)
                  Keith Rice

                  Hi Alex,

                   

                  The API Help was written for programmers, not for mechanical engineers. That's why it is so hard to use right off the bat. I have video tutorials at my web site that will walk you through how to use the SolidWorks API Help. Not just lesson 2.1 but also the video called "Taking Macros to the People" at the bottom of the Videos page.

                   

                  Also note that you shouldn't use IModelDocExtension::SelectByID2 to select edges. There are more reliable ways to select edges, such as via traversal and IEntity::Select. I cover those topics in my course as well (lesson 3.4 and lesson 4.3), though they aren't free.

                   

                  If you plan on attempting to figure it all out on your own, I would suggest you start with the fundamentals of API programming and work your way up. Traversal in particular is a deep topic and not one that can be explained in a single forum post. Once you're comfortable with some of the fundamentals, you'll be able to ask more specific questions here in the forums.

                   

                  Keith

                  SolidWorks API Training