2 Replies Latest reply on Jun 29, 2016 10:06 PM by Alin Vargatu

    Macro for thickening each selected face as an individual body.

    Alin Vargatu

      The model contains a number of faces that belong to one or more surface bodies.

       

      I would like to preselect a number of these faces type a value "T". The macro will:

       

      1. Copy each of the selected faces into a new and independent surface body

      2. Thicken all the new surface bodies with the thickness = "T" without merging the new solid bodies. If needed, the direction of the thickening could be changed.

      3. As an option, delete the old surface bodies. (not imperative)

       

      I found this macro, but does not seem to work in SW 2016. Wicked thickening challenge

       

      Any assistance will be greatly appreciated.

        • Re: Macro for thickening each selected face as an individual body.
          Viktor Bovzdarenko

          Hi Alin

          I also answered on another thread:Wicked thickening challenge

          Macro  works in SW16.

           

          Option Explicit

          Sub main()

              On Error Resume Next

              Const Thickness As Double = -0.001

           

              Dim swApp              As SldWorks.SldWorks: Set swApp = CreateObject("SldWorks.Application")

              Dim swModel            As SldWorks.ModelDoc2: Set swModel = swApp.ActiveDoc

              Dim swSelMgr            As SldWorks.SelectionMgr: Set swSelMgr = swModel.SelectionManager

              Dim swSelData          As SldWorks.SelectData: Set swSelData = swSelMgr.CreateSelectData

              Dim swPart              As SldWorks.PartDoc: Set swPart = swModel

              Dim swBody              As SldWorks.Body2

              Dim swFace              As SldWorks.Face

              Dim swEnt              As SldWorks.Entity

              Dim i                  As Long

           

              Dim vBodies As Variant: vBodies = swPart.GetBodies2(swAllBodies, True)

              For i = LBound(vBodies) To UBound(vBodies)

                  Set swBody = vBodies(i)

                  Set swFace = swBody.GetFirstFace

                  Do Until swFace Is Nothing

                      Set swEnt = swFace

                      swFace.Select4 False, swSelData

                      swModel.InsertOffsetSurface Thickness, True

                      Set swFace = swFace.GetNextFace

                  Loop

                  swBody.Select2 False, swSelData

                  swModel.FeatureManager.InsertDeleteBody

              Next

              vBodies = swPart.GetBodies2(swAllBodies, True)

              For i = LBound(vBodies) To UBound(vBodies)

                  Set swBody = vBodies(i)

                  Set swFace = swBody.GetFirstFace

                  Set swEnt = swFace

                  swFace.Select4 False, swSelData

                  swSelData.Mark = 1

                  swFace.Select4 False, swSelData

                  swModel.FeatureManager.FeatureBossThicken Thickness, 0, 96, False, False, False, False

              Next

          End Sub