Rene Wolters

copy config.spec. properties to custom properties and delete all config.spec. propertiers

Discussion created by Rene Wolters on Mar 24, 2020
Latest reply on Mar 25, 2020 by Deepak Gupta



I working an a macro to extract configurations from a aesigntable Part. Compareable to the famous ConfigRipper.

Unfortunately I'm not a programmer on daily basis but found enough ideas for getting so far and now

the only thing missing is:


I'm not able to copy the configuration specific properties to the custom properties and after that delete all configuration specific properties.


here is the code of my subroutine:


Sub RemoveConfigurations(filePath As String, confToKeep As String)

    On Error GoTo catch
    Debug.Print filePath
    Debug.Print confToKeep
    Dim swModel As SldWorks.ModelDoc2
    Dim boolstatus As Boolean
    Dim cusPropMgr As SldWorks.CustomPropertyManager
    Dim nNbrProps As Long
    Dim value As Integer
    Dim vPropNames As Variant
    Dim vPropTypes As Variant
    Dim vPropValues As Variant
    Dim resolved As Variant
Dim lRetVal As Long
Dim lRetVal2 As Long
Dim lRetVal3 As Long
Dim lRetVal4 As Long
Dim lRetVal5 As Long

Dim config As SldWorks.Configuration


Dim ResolvedValOut As String
Dim wasResolved As Boolean
Dim swDocSpec As SldWorks.DocumentSpecification
Set swDocSpec = swApp.GetOpenDocSpec(filePath)
swApp.DocumentVisible False, swDocumentTypes_e.swDocPART
Set swModel = swApp.OpenDoc7(swDocSpec)
swApp.DocumentVisible True, swDocumentTypes_e.swDocPART
Set cusPropMgr = swModel.Extension.CustomPropertyManager(Empty) 'config.CustomPropertyManager
swModel.ShowConfiguration2 confsToKeep
    Dim vConfNames As Variant
    vConfNames = swModel.GetConfigurationNames
    Dim i As Integer
    Set config = swModel.GetActiveConfiguration
    Set cusPropMgr = config.CustomPropertyManager


    For i = 0 To UBound(vConfNames)
              Dim confName As String
        confName = CStr(vConfNames(i))
        Part.ShowConfiguration2 confName
        If Not confToKeep = confName Then
            swModel.DeleteConfiguration2 confName
            Debug.Print confToKeep
            Debug.Print confName
             ' Get the number of custom properties for this configuration
            nNbrProps = cusPropMgr.Count
            ' Get the names of the custom properties
            'lRetVal =   'cusPropMgr.GetAll vPropNames, vPropTypes, vPropValues
            'get property names

            For k = 0 To UBound(vConfNames)
               Set cusPropMgr = swModel.Extension.CustomPropertyManager(vConfNames(i))
               cusPropMgr.GetAll vPropNames, vPropTypes, vPropValues


'Comment : here the counting of the config propertiers goes wrong, I hav 22 Properties, but Ubound is over 38

' and the the process runs into an error

               If Not IsEmpty(vPropNames) Then 
                    For j = 0 To UBound(vPropNames) 'Delete all custom properties for each configuration.
                        Debug.Print sConfigName & vPropNames(j) & vPropValues(j)
                       lRetVal2 = cusPropMgr.Delete2(vPropNames(j))
                    Next j
                End If

        End If

Set cusPropMgr = Nothing 'Clean


     bRebuild = Part.ForceRebuild3(False)
    'If False <> swModel.Extension.HasDesignTable() Then
        swModel.DeleteDesignTable ' delete design table in saved part


   ' renaming the config

    boolstatus = swModel.EditConfiguration3(confToKeep, "Standard", "", confToKeep, 32)


There are 22 config specific properties, but Ubound always states there are 38 and the deleteing process runs into an error. It somehow seems that the properties are counted twice


Can someone give me a hint, what I did wrong here?