14 Replies Latest reply on May 21, 2017 12:16 AM by Josh Brady

    vba macro to get thickness of a part

    Nadav Gover

      Hi all,

      Is there a way to get the thickness of a part? I don't know on which face it was sketched on (top, front, etc.).

      Also some part have cuts that are not through all, is there a way to get all thicknesses?

      Maybe there is a way to retrieve this information from a solid drawing?


      Thank you

        • Re: vba macro to get thickness of a part
          Peter Brinkhuis

          Can you show us an example picture? How did you get the file, is it an imported file?

          • Re: vba macro to get thickness of a part
            Christian Chu

            Not sure what you want to achieve here, how's about measure command ?

            • Re: vba macro to get thickness of a part
              Nick Gvk

              how about using the model items button












              the thickness of a part is a a strange thing to determain

              the thickness wil be depending on wich plane the part has been drawn

              and also on how  u are planning to use the part and how to make the part as the end product ( sheet , round bar, square bar , forging , casting )

              in this case its obvius as i inserterted the isometric view of it


              mayby for sheet metal there is an option to display the thickness

              or in structure it can be displayed in the cutting list but thats only for the stuff u pre define

              • Re: vba macro to get thickness of a part
                Ivana Kolin

                open part doc and select any face. Then try this macro:

                Option Explicit
                Sub main()
                    Dim swApp As SldWorks.SldWorks
                    Dim swModel As SldWorks.ModelDoc2
                    Dim swPart As SldWorks.PartDoc
                    Dim swSelMgr As SldWorks.SelectionMgr
                    Dim swFace As SldWorks.Face2
                    Dim arrBody As Variant
                    Dim Body As Variant
                    Dim arrFaces As Variant
                    Dim face As Variant
                    Dim swFace2 As SldWorks.Face2
                    Dim swBody As SldWorks.Body2
                    Dim vPoint1 As Variant
                    Dim vPoint2 As Variant
                    Dim nDist As Double
                    Dim v As MathVector
                    Dim v2 As MathVector
                    Dim swMath As SldWorks.MathUtility
                    Dim swMeasure As SldWorks.measure
                    Set swApp = Application.SldWorks
                    Set swMath = swApp.GetMathUtility
                    Set swModel = swApp.ActiveDoc
                    Set swPart = swModel
                    If swPart Is Nothing Then Exit Sub
                    Set swSelMgr = swModel.SelectionManager
                    If swSelMgr.GetSelectedObjectCount2(-1) <> 1 Then Exit Sub
                    If swSelMgr.GetSelectedObjectType3(1, -1) <> swSelFACES Then Exit Sub
                    Set swFace = swSelMgr.GetSelectedObject6(1, -1)
                    Set v = swMath.CreateVector(swFace.Normal)
                    Set swMeasure = swModel.Extension.CreateMeasure
                    arrBody = swPart.GetBodies2(swSolidBody, True)
                    If IsEmpty(arrBody) Then Exit Sub
                    For Each Body In arrBody
                        Set swBody = Body
                        arrFaces = swBody.GetFaces
                        For Each face In arrFaces
                            Set swFace2 = face
                            Set v2 = swMath.CreateVector(swFace2.Normal)
                            If Abs(v.Dot(v2)) = 1 And swApp.IsSame(swFace2, swFace) = swObjectNotSame Then
                                'swFace2.Select4 False, Nothing
                                nDist = swModel.ClosestDistance(swFace, swFace2, vPoint1, vPoint2) * 1000
                                Debug.Print nDist
                            End If
                End Sub
                • Re: vba macro to get thickness of a part
                  Amen Allah Jlili

                  Interesting question!


                  I think the closest definition to a thickness in 3D is the normal distance between the two equal, largest, planar faces of a part. Once you identify these two large faces. You can pretty much get other thickness  by comparing one of these faces and the other faces (much like Ivana Kolin did).