2 Replies Latest reply on Apr 28, 2014 2:54 PM by Thomas Hellm

    A marco that can change custom properties

    Thomas Hellm

      I have an project and I want to change all of the part numbers. The change will be adding 1000 to them i.e. #23 will become #1023. I have not writing a VB program in many years and have found sample codes I can use to help solve this issue but I can figure out how to make the program get the old part number so I can just add the 1000 to it and create a new number.

        • Re: A marco that can change custom properties
          Keith Rice



          The following code must be run with a part open. It will extract the value of a custom property called "PartNo". If that value has a pound sign, it will be stripped. 1000 will be added, then the PartNo custom property will be reset with a pound sign on the front again.




          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swCustPropMgr As SldWorks.CustomPropertyManager

          Dim strPartNo As String

          Dim dblPartNo As Double


          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc


              If swModel Is Nothing Then Exit Sub

              If swModel.GetType <> swDocPART Then Exit Sub


              Set swCustPropMgr = swModel.Extension.CustomPropertyManager(Empty)


              strPartNo = swCustPropMgr.Get("PartNo")


              strPartNo = Replace(strPartNo, "#", Empty)


              If IsNumeric(strPartNo) = False Then Exit Sub


              dblPartNo = strPartNo


              dblPartNo = dblPartNo + 1000


              swCustPropMgr.Set "PartNo", "#" & dblPartNo

          End Sub




          I am sure that you can modify this macro for your own needs. Please mark this answer as correct if it helped.



          SolidWorks API Tutorials