4 Replies Latest reply on Jun 21, 2017 3:10 AM by Sridhar S.

    How to change the custom properties for configuration?

    Sridhar S.

      Hi,

      I have a code to change custom property for Solidworks Part File. The Code is below.

      =============================================================

      Option Explicit

      Dim swApp               As SldWorks.SldWorks

      Dim swModel             As SldWorks.ModelDoc2

      Sub main()

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      swModel.CustomInfo("Revision") = "A"

      swModel.ForceRebuild

      swModel.Save

      End Sub

      =============================================================

      It only changes the revision letter in Custom Property, But it does not change the Revision in "Configuration Specific".

      Some parts have 2 configurations and some have more than 10 configuration.

       

      How can I change this code to change "Revision" letter for all configuration.

      Many Thanks in Advance.

        • Re: How to change the custom properties for configuration?
          Solid Air

          The code you have is quite old; the custominfo command is obsolete.  Below is code from API help: Get Custom Properties for Configuration Example (VBA)

          '---------------------------------------------------------------------------
          ' Preconditions:
          ' 1. Open a part document.
          ' 2. Open the Immediate window.
          '
          ' Postconditions:
          ' 1. Adds a date custom property to the part's configuration.
          ' 2. Deletes the custom property from the configuration.
          ' 3. Examine the Immediate window.
          '---------------------------------------------------------------------------

          Option Explicit

          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim config As SldWorks.Configuration
          Dim cusPropMgr As SldWorks.CustomPropertyManager
          Dim lRetVal As Long
          Dim vPropNames As Variant
          Dim vPropTypes As Variant
          Dim vPropValues As Variant
          Dim ValOut As String
          Dim ResolvedValOut As String
          Dim wasResolved As Boolean
          Dim resolved As Variant
          Dim nNbrProps As Long
          Dim j As Long
          Dim custPropType As Long

          Sub main()

              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set config = swModel.GetActiveConfiguration
             

              Set cusPropMgr = config.CustomPropertyManager
             

              lRetVal = cusPropMgr.Add3("ADATE", swCustomInfoType_e.swCustomInfoDate, "4-13-59", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
              lRetVal = cusPropMgr.Get5("ADATE", False, ValOut, ResolvedValOut, wasResolved)
              lRetVal = cusPropMgr.Set2("ADATE", "4-13-89")
             

              ' Get the number of custom properties for this configuration
              nNbrProps = cusPropMgr.Count
              Debug.Print "Number of properties for this configuration:            " & nNbrProps
             

              ' Get the names of the custom properties
              lRetVal = cusPropMgr.GetAll2(vPropNames, vPropTypes, vPropValues, resolved)

             ' For each custom property, print its type, value, and resolved value
              For j = 0 To nNbrProps - 1
                  custPropType = cusPropMgr.GetType2(vPropNames(j))
                  Debug.Print "    Name, swCustomInfoType_e value, and resolved value:  " & vPropNames(j) & ", "; custPropType & ", " & ResolvedValOut
              Next j

              lRetVal = cusPropMgr.Delete2("ADATE")
              ' Get the number of custom properties for this configuration
              nNbrProps = cusPropMgr.Count
              Debug.Print "Number of properties for this configuration:            " & nNbrProps

          End Sub

            • Re: How to change the custom properties for configuration?
              Sridhar S.

              Thanks for your quick Reply Solid Air, I am new to VBA codes So can you help me to change Revision Letter for all configurations?

                • Re: How to change the custom properties for configuration?
                  Solid Air

                  Try this.

                   

                  Option Explicit

                  Dim swApp As SldWorks.SldWorks

                  Dim swModel As SldWorks.ModelDoc2

                  Dim swConfig As SldWorks.Configuration

                  Dim swCustPropMgr As SldWorks.CustomPropertyManager

                   

                  Dim vConfigNames As Variant

                  Dim vConfigName As Variant

                   

                  Dim sValout As String

                  Dim sResValout As String

                   

                  Dim bWasRes As Boolean

                   

                  Sub main()

                   

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                    

                      vConfigNames = swModel.GetConfigurationNames

                    

                      For Each vConfigName In vConfigNames

                    

                          Set swConfig = swModel.IGetConfigurationByName(vConfigName)

                          Set swCustPropMgr = swConfig.CustomPropertyManager

                        

                          'custom property does not exist

                          If swCustPropMgr.Get5("Revision", False, sValout, sResValout, bWasRes) = 1 Then

                        

                              swCustPropMgr.Add3 "Revision", swCustomInfoType_e.swCustomInfoText, "A", swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew

                            

                          'custom property exists

                          Else

                        

                              swCustPropMgr.Set2 "Revision", "A"

                            

                          End If

                        

                      Next

                    

                      Set swApp = Nothing

                      Set swModel = Nothing

                      Erase vConfigNames

                    

                  End Sub