3 Replies Latest reply on Nov 5, 2015 7:27 AM by Claudius Claudius

    get area of offset surface

    Eric Bunn

      I found this little piece of code in the forum posted by Keith Rice for getting the area of a face.  It works very well.  I want to get the area of an offset surface and the code will not work on the offset surface.  Can anyone tell me how to reconfigure it to do an offset surface?

       

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swSelMgr As SldWorks.SelectionMgr

      Dim swFace As SldWorks.Face2

      Dim swFaceArea As Double

       

      Sub main()

       

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swSelMgr = swModel.SelectionManager

       

          Set swFace = swSelMgr.GetSelectedObject6(1, -1) 'Gets Selected Face

          swFaceArea = Round(swFace.GetArea * 1550, 3) 'Prints Area of Selected Face

          Debug.Print swFaceArea & " in^2"

         

      End Sub

        • Re: get area of offset surface
          Jim Sculley

          This code seems to work fine for me.  Can you post a picture showing the surface in question?

            • Re: get area of offset surface
              Eric Bunn

              Jim,

               

              As it turns out the code did work if I pre-selected the offset surface by hand first.  What I left out of the last post was my attempt to pre-select the surface using SelectByID2.  The attached code works (bottom of page).  I used the macro recorder to get the selection code:

               

              boolstatus = swModel.Extension.SelectByID2("", "FACE", 0.177799999999991, 6.65776655689001E-02, 0.150677716671453, False, 0, Nothing, 0)

               

              Is there another way to select the surface?  I tried to simplify the line by changing it to the following and it did not work:

               

              boolstatus = swModel.Extension.SelectByID2("Surface-Offset1", "FACE", 0, 0, 0, False, 0, Nothing, 0)

               

               

              This code works:

               

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swSelMgr As SldWorks.SelectionMgr

              Dim swFace As SldWorks.Face2

              Dim swFaceArea As Double

              Dim boolstatus As Boolean

              Dim longstatus As Long, longwarnings As Long

               

               

               

              Sub main()

               

               

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  Set swSelMgr = swModel.SelectionManager

               

               

                  boolstatus = swModel.Extension.SelectByID2("", "FACE", 0.177799999999991, 6.65776655689001E-02, 0.150677716671453, False, 0, Nothing, 0)

                 

                  Set swFace = swSelMgr.GetSelectedObject6(1, -1) 'Gets Selected Face

               

               

                  swFaceArea = Round(swFace.GetArea * 1550, 3)

                 

                  Debug.Print swFaceArea & " in^2" 'Prints Area of Selected Face

                  swModel.ClearSelection2 True

                 

              End Sub