We’re rewarding the question askers & reputations are being recalculated! Read more.
5 edited tags
| link
4 Rollback to Revision 2
source | link

I've edited my code to just reflect the part in question, rather than the whole procedure.

Private Function GetModelProps(ByRef swCustPropMgr As SldWorks.CustomPropertyManager, Optional ByVal dicInput As Scripting.Dictionary) As Scripting.Dictionary
'This procedure gets the properties from a custom property manager object that is passed by the calling procedure.  It returns a dictionary object containing the properties found.

'Declare constants
    Const strNonsense           As String = "SKDjf09sf!@&#(@#$&!(*^)_!@0-12-849uj0394jfIODJS(G_3r5902-129381203892193018"  'This is just a nonsense string that will never be entered in a custom property

'Declare variables
    Dim lngX                    As Long
    Dim strProps()              As String
    Dim strProp                 As String
    Dim strPropStatement        As String
    Dim strPropVal              As String
    Dim dicProps                As Scripting.Dictionary

'Do 
 some stuff  On Error GoTo CleanExit

'Initialize dictionary object
    Set dicProps = New Scripting.Dictionary

    'Pass values from the input dictionary if one was provided
        If Not dicInput Is Nothing Then
                If Not IsArrayEmpty(dicInput.Keys) Then
                        For lngX = LBound(dicInput.Keys) To UBound(dicInput.Keys)
                            DicMergeOnKey dicProps, dicInput, (dicInput.Keys(lngX))
                        Next
                End If
        End If

'Attempt to populateget anthe arraynames withof all the custom properties. IIf wantthere toare retrieveno custom properties the valuesarray forwill not be initialized and populated.
    On Error Resume Next
    strProps = swCustPropMgr.GetNames
    On Error 'LoopGoTo throughCleanExit

 all   'Check to see if the array is empty - if it is, then there are no custom properties into get
        If Not IsArrayEmpty(strProps) Then

            'Loop through all the arraycustom properties
                For lngX = 0 To UBound(strProps)
                'Get the custom property name
                    strProp = strProps(lngX)
                'Set initial value to a string that will never be found
                    strPropVal = strNonsense
                'The Get2 method takes one input and returns 2 strings:  Input: Property name, Output1: Property statment, Output2: Evalutated property value
                    swCustPropMgr.Get2 strProp, strPropStatement, strPropVal

                    'Sometimes this can take a while to execute, so we use the loop below to wait until the system is done processing all other events
                        While strPropVal = strNonsense
                            DoEvents
                        Wend 

                    'Make the property uppercase so we don't accidentally add multiple properties due to difference in case between documents
                        strProp = UCase(strProp)

                    'Verify item numbers before adding
                        If strProp Like "PARTNO" Then
                            strPropVal = ValidateLokItem(Trim(strPropVal))
                        End If

                    'Add the returned value to the dictionary.
                        If Len(strPropVal) > 0 Then
                            If Not dicProps.Exists(strProp) Then
                                dicProps.Add strProp, strPropVal
                            Else
                                dicProps.ITEM(strProp) = strPropVal
                            End If
                        End If
                Next
        End If
'Do
'Return somethe moredictionary to the calling procedure
    Set GetModelProps = dicProps

CleanExit:
    Set dicProps = Nothing
    Set dicInput = Nothing
    Erase strProps
End Function

I've edited my code to just reflect the part in question, rather than the whole procedure.

Private Function GetModelProps(ByRef swCustPropMgr As SldWorks.CustomPropertyManager, Optional ByVal dicInput As Scripting.Dictionary) As Scripting.Dictionary

'Declare constants
    Const strNonsense           As String = "SKDjf09sf!@&#(@#$&!(*^)_!@0-12-849uj0394jfIODJS(G_3r5902-129381203892193018"  'This is just a nonsense string that will never be entered in a custom property

'Declare variables
    Dim lngX                    As Long
    Dim strProps()              As String
    Dim strProp                 As String
    Dim strPropStatement        As String
    Dim strPropVal              As String
    Dim dicProps                As Scripting.Dictionary

'Do some stuff to populate an array with custom properties I want to retrieve the values for.

            'Loop through all the custom properties in the array
                For lngX = 0 To UBound(strProps)
                'Get the custom property name
                    strProp = strProps(lngX)
                'Set initial value to a string that will never be found
                    strPropVal = strNonsense
                'The Get2 method takes one input and returns 2 strings:  Input: Property name, Output1: Property statment, Output2: Evalutated property value
                    swCustPropMgr.Get2 strProp, strPropStatement, strPropVal

                    'Sometimes this can take a while to execute, so we use the loop below to wait until the system is done processing all other events
                        While strPropVal = strNonsense
                            DoEvents
                        Wend
                Next

'Do some more

End Function
Private Function GetModelProps(ByRef swCustPropMgr As SldWorks.CustomPropertyManager, Optional ByVal dicInput As Scripting.Dictionary) As Scripting.Dictionary
'This procedure gets the properties from a custom property manager object that is passed by the calling procedure.  It returns a dictionary object containing the properties found.

'Declare constants
    Const strNonsense           As String = "SKDjf09sf!@&#(@#$&!(*^)_!@0-12-849uj0394jfIODJS(G_3r5902-129381203892193018"  'This is just a nonsense string that will never be entered in a custom property

'Declare variables
    Dim lngX                    As Long
    Dim strProps()              As String
    Dim strProp                 As String
    Dim strPropStatement        As String
    Dim strPropVal              As String
    Dim dicProps                As Scripting.Dictionary

 
    On Error GoTo CleanExit

'Initialize dictionary object
    Set dicProps = New Scripting.Dictionary

    'Pass values from the input dictionary if one was provided
        If Not dicInput Is Nothing Then
                If Not IsArrayEmpty(dicInput.Keys) Then
                        For lngX = LBound(dicInput.Keys) To UBound(dicInput.Keys)
                            DicMergeOnKey dicProps, dicInput, (dicInput.Keys(lngX))
                        Next
                End If
        End If

'Attempt to get the names of all the custom properties. If there are no custom properties the array will not be initialized and populated.
    On Error Resume Next
    strProps = swCustPropMgr.GetNames
    On Error GoTo CleanExit

    'Check to see if the array is empty - if it is, then there are no custom properties to get
        If Not IsArrayEmpty(strProps) Then

            'Loop through all the custom properties
                For lngX = 0 To UBound(strProps)
                'Get the custom property name
                    strProp = strProps(lngX)
                'Set initial value to a string that will never be found
                    strPropVal = strNonsense
                'The Get2 method takes one input and returns 2 strings:  Input: Property name, Output1: Property statment, Output2: Evalutated property value
                    swCustPropMgr.Get2 strProp, strPropStatement, strPropVal

                    'Sometimes this can take a while to execute, so we use the loop below to wait until the system is done processing all other events
                        While strPropVal = strNonsense
                            DoEvents
                        Wend 

                    'Make the property uppercase so we don't accidentally add multiple properties due to difference in case between documents
                        strProp = UCase(strProp)

                    'Verify item numbers before adding
                        If strProp Like "PARTNO" Then
                            strPropVal = ValidateLokItem(Trim(strPropVal))
                        End If

                    'Add the returned value to the dictionary.
                        If Len(strPropVal) > 0 Then
                            If Not dicProps.Exists(strProp) Then
                                dicProps.Add strProp, strPropVal
                            Else
                                dicProps.ITEM(strProp) = strPropVal
                            End If
                        End If
                Next
        End If

'Return the dictionary to the calling procedure
    Set GetModelProps = dicProps

CleanExit:
    Set dicProps = Nothing
    Set dicInput = Nothing
    Erase strProps
End Function
3 deleted 2136 characters in body
source | link

I've edited my code to just reflect the part in question, rather than the whole procedure.

Private Function GetModelProps(ByRef swCustPropMgr As SldWorks.CustomPropertyManager, Optional ByVal dicInput As Scripting.Dictionary) As Scripting.Dictionary
'This procedure gets the properties from a custom property manager object that is passed by the calling procedure.  It returns a dictionary object containing the properties found.

'Declare constants
    Const strNonsense           As String = "SKDjf09sf!@&#(@#$&!(*^)_!@0-12-849uj0394jfIODJS(G_3r5902-129381203892193018"  'This is just a nonsense string that will never be entered in a custom property

'Declare variables
    Dim lngX                    As Long
    Dim strProps()              As String
    Dim strProp                 As String
    Dim strPropStatement        As String
    Dim strPropVal              As String
    Dim dicProps                As Scripting.Dictionary


    On Error GoTo CleanExit

'Initialize dictionary object
    Set dicProps = New Scripting.Dictionary

    'Pass values from the input dictionary if one was provided
        If Not dicInput Is Nothing Then
                If Not IsArrayEmpty(dicInput.Keys) Then
                        For lngX = LBound(dicInput.Keys) To UBound(dicInput.Keys)
                            DicMergeOnKey dicProps, dicInput, (dicInput.Keys(lngX))
                        Next
                End If
       'Do Endsome If

'Attemptstuff to get the namespopulate ofan allarray thewith custom properties. If there areI nowant customto propertiesretrieve the array will not be initialized andvalues populatedfor.
    On Error Resume Next
    strProps = swCustPropMgr.GetNames
    On Error GoTo CleanExit

    'Check to'Loop seethrough ifall the array is empty - if it is, then there are no custom properties to get
        If Not IsArrayEmpty(strProps) Then

            'Loop through allin the custom propertiesarray
                For lngX = 0 To UBound(strProps)
                'Get the custom property name
                    strProp = strProps(lngX)
                'Set initial value to a string that will never be found
                    strPropVal = strNonsense
                'The Get2 method takes one input and returns 2 strings:  Input: Property name, Output1: Property statment, Output2: Evalutated property value
                    swCustPropMgr.Get2 strProp, strPropStatement, strPropVal

                    'Sometimes this can take a while to execute, so we use the loop below to wait until the system is done processing all other events
                        While strPropVal = strNonsense
                            DoEvents
                        Wend
 
                    'Make the property uppercase so we don't accidentally add multiple properties due to difference in case between documents
                        strProp = UCase(strProp)

                    'Verify item numbers before adding
                        If strProp Like "PARTNO" Then
                            strPropVal = ValidateLokItem(Trim(strPropVal))
                        End If

                    'Add the returned value to the dictionary.
                        If Len(strPropVal) > 0 Then
                            If Not dicProps.Exists(strProp) Then
                                dicProps.Add strProp, strPropVal
                            Else
                                dicProps.ITEM(strProp) = strPropVal
                            End If
                        End If
                Next
        End If

'Return the dictionary to the calling procedure
    Set GetModelProps = dicProps

CleanExit:
    Set dicProps = Nothing
    Set dicInput'Do =some Nothingmore
    Erase strProps
End Function
Private Function GetModelProps(ByRef swCustPropMgr As SldWorks.CustomPropertyManager, Optional ByVal dicInput As Scripting.Dictionary) As Scripting.Dictionary
'This procedure gets the properties from a custom property manager object that is passed by the calling procedure.  It returns a dictionary object containing the properties found.

'Declare constants
    Const strNonsense           As String = "SKDjf09sf!@&#(@#$&!(*^)_!@0-12-849uj0394jfIODJS(G_3r5902-129381203892193018"  'This is just a nonsense string that will never be entered in a custom property

'Declare variables
    Dim lngX                    As Long
    Dim strProps()              As String
    Dim strProp                 As String
    Dim strPropStatement        As String
    Dim strPropVal              As String
    Dim dicProps                As Scripting.Dictionary


    On Error GoTo CleanExit

'Initialize dictionary object
    Set dicProps = New Scripting.Dictionary

    'Pass values from the input dictionary if one was provided
        If Not dicInput Is Nothing Then
                If Not IsArrayEmpty(dicInput.Keys) Then
                        For lngX = LBound(dicInput.Keys) To UBound(dicInput.Keys)
                            DicMergeOnKey dicProps, dicInput, (dicInput.Keys(lngX))
                        Next
                End If
        End If

'Attempt to get the names of all the custom properties. If there are no custom properties the array will not be initialized and populated.
    On Error Resume Next
    strProps = swCustPropMgr.GetNames
    On Error GoTo CleanExit

    'Check to see if the array is empty - if it is, then there are no custom properties to get
        If Not IsArrayEmpty(strProps) Then

            'Loop through all the custom properties
                For lngX = 0 To UBound(strProps)
                'Get the custom property name
                    strProp = strProps(lngX)
                'Set initial value to a string that will never be found
                    strPropVal = strNonsense
                'The Get2 method takes one input and returns 2 strings:  Input: Property name, Output1: Property statment, Output2: Evalutated property value
                    swCustPropMgr.Get2 strProp, strPropStatement, strPropVal

                    'Sometimes this can take a while to execute, so we use the loop below to wait until the system is done processing all other events
                        While strPropVal = strNonsense
                            DoEvents
                        Wend
 
                    'Make the property uppercase so we don't accidentally add multiple properties due to difference in case between documents
                        strProp = UCase(strProp)

                    'Verify item numbers before adding
                        If strProp Like "PARTNO" Then
                            strPropVal = ValidateLokItem(Trim(strPropVal))
                        End If

                    'Add the returned value to the dictionary.
                        If Len(strPropVal) > 0 Then
                            If Not dicProps.Exists(strProp) Then
                                dicProps.Add strProp, strPropVal
                            Else
                                dicProps.ITEM(strProp) = strPropVal
                            End If
                        End If
                Next
        End If

'Return the dictionary to the calling procedure
    Set GetModelProps = dicProps

CleanExit:
    Set dicProps = Nothing
    Set dicInput = Nothing
    Erase strProps
End Function

I've edited my code to just reflect the part in question, rather than the whole procedure.

Private Function GetModelProps(ByRef swCustPropMgr As SldWorks.CustomPropertyManager, Optional ByVal dicInput As Scripting.Dictionary) As Scripting.Dictionary

'Declare constants
    Const strNonsense           As String = "SKDjf09sf!@&#(@#$&!(*^)_!@0-12-849uj0394jfIODJS(G_3r5902-129381203892193018"  'This is just a nonsense string that will never be entered in a custom property

'Declare variables
    Dim lngX                    As Long
    Dim strProps()              As String
    Dim strProp                 As String
    Dim strPropStatement        As String
    Dim strPropVal              As String
    Dim dicProps                As Scripting.Dictionary

'Do some stuff to populate an array with custom properties I want to retrieve the values for.

            'Loop through all the custom properties in the array
                For lngX = 0 To UBound(strProps)
                'Get the custom property name
                    strProp = strProps(lngX)
                'Set initial value to a string that will never be found
                    strPropVal = strNonsense
                'The Get2 method takes one input and returns 2 strings:  Input: Property name, Output1: Property statment, Output2: Evalutated property value
                    swCustPropMgr.Get2 strProp, strPropStatement, strPropVal

                    'Sometimes this can take a while to execute, so we use the loop below to wait until the system is done processing all other events
                        While strPropVal = strNonsense
                            DoEvents
                        Wend
                Next

'Do some more

End Function
2 moved actual question to opening statement
source | link
1
source | link