6 Replies Latest reply on Dec 12, 2014 10:53 AM by H. Kemper

    How to change thickness of a sheet metal part via API

    H. Kemper

      Is it possible to change the thickness of a sheet metal part via API?

      I have found in the api help the code to change the bend radius (see: 2014 SolidWorks API Help - Change Bend Radius of Sheet Metal Part Example (VBA) )

      and added a few lines to change the thickness. But the thickness does not change.

      What do I do wrong?



      Here is the code i found and changed a little:



      ' Preconditions:

      '       (1) Part document containing sheet metal part is open.

      '       (2) Sheet-Metal feature is selected.


      ' Postconditions: Default bend radius value is doubled.



      Option Explicit

      Sub main()

          Dim swApp                   As SldWorks.SldWorks

          Dim swModel                 As SldWorks.ModelDoc2

          Dim swSelMgr                As SldWorks.SelectionMgr

          Dim swFeat                  As SldWorks.Feature

          Dim swSheetMetal            As SldWorks.SheetMetalFeatureData

          Dim bRet                    As Boolean

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swSelMgr = swModel.SelectionManager

          Set swFeat = swSelMgr.GetSelectedObject5(1)

          Set swSheetMetal = swFeat.GetDefinition

      MsgBox swSheetMetal.Thickness

          Debug.Print "Feature = " & swFeat.Name

          Debug.Print "  BendRadius = " & swSheetMetal.BendRadius * 1000# & " mm"


         ' Rollback to change default bend radius

          bRet = swSheetMetal.AccessSelections(swModel, Nothing): Debug.Assert bRet

          swSheetMetal.BendRadius = 2# * swSheetMetal.BendRadius

          swSheetMetal.Thickness = 2

      MsgBox swSheetMetal.Thickness

         ' Apply changes

          bRet = swFeat.ModifyDefinition(swSheetMetal, swModel, Nothing): Debug.Assert bRet

      MsgBox swSheetMetal.Thickness

      End Sub



      Thanks in advance,


      Henk Kemper