MACRO LIBRARY

Apply All Dimension Values to All Configurations

Free public access. No account or subscription required.

Instructions

This macro changes the configuration settings on all dimensions in the part to apply to all configurations. (Consequently, whatever configuration contains the desired dimensions should be active.) All configurations are then traversed and rebuilt.

Preconditions
part is open

Files

Apply Dimension Value to All Configurations

Code

'This macro changes the configuration settings on all dimensions in the part to apply to _
    all configurations. (Consequently, whatever configuration contains the desired dimensions _
    should be active.) All configurations are then traversed and rebuilt.
    
'Preconditions: part is open
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swFeat As SldWorks.Feature
    Dim swDispDim As SldWorks.DisplayDimension
    Dim swDim As SldWorks.Dimension
    Dim i As Integer
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    'turn on "feature dimension" doc option (see notes)
    swModel.Extension.SetUserPreferenceToggle swDisplayFeatureDimensions, _
        swDetailingNoOptionSpecified, True
    
    'traverse all dimensions and modify dimension configuration
    Set swFeat = swModel.FirstFeature
    While Not swFeat Is Nothing
        Set swDispDim = swFeat.GetFirstDisplayDimension
        While Not swDispDim Is Nothing
            If swFeat.GetTypeName = "Chamfer" Then
                For i = 0 To 1
                    Set swDim = swDispDim.GetDimension2(i)
                    Call ModifyDimension(swDim)
                Next i
            Else
                Set swDim = swDispDim.GetDimension2(Empty)
                Call ModifyDimension(swDim)
            End If
            Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
        Wend
        Set swFeat = swFeat.GetNextFeature
    Wend
    
    'turn off "feature dimension" doc option
    swModel.Extension.SetUserPreferenceToggle swDisplayFeatureDimensions, _
        swDetailingNoOptionSpecified, False
    
    'get name of currently active config
    Dim strOrigConfigName As String
    Dim swConfig As SldWorks.Configuration
    Set swConfig = swModel.ConfigurationManager.ActiveConfiguration
    strOrigConfigName = swConfig.Name
    
    'traverse all configurations and rebuild them
    Dim vConfigNames As Variant
    vConfigNames = swModel.GetConfigurationNames
    For i = 0 To UBound(vConfigNames)
        swModel.ShowConfiguration2 vConfigNames(i)
        swModel.ForceRebuild3 False
    Next i
    
    're-show originally activate configuration
    swModel.ShowConfiguration2 strOrigConfigName
End Sub
    
Sub ModifyDimension(swDim As SldWorks.Dimension)
    Dim vDimVal As Variant
    vDimVal = swDim.GetSystemValue3(swThisConfiguration, Nothing)
    swDim.SetSystemValue3 vDimVal(0), swAllConfiguration, Nothing
End Sub
    
'Notes: dimensions are traversed in a part using IFeature::GetFirstDisplayDimension in _
    combination with IFeature::GetNextDisplayDimension. Before this will work, however, _
    you must turn on the Feature Dimensions display filter in Options-->Document-->Detailing
    
'Chamfer dimensions are obtained through the index of IDisplayDimension::GetDimension2. _
    See API Help for more info.