MACRO LIBRARY

Change driven / driving state of selected dimensions

Free public access. No account or subscription required.

Files

Change driven / driving state of selected dimensions

Code

'Change selected dimensions to driven if driving, and vice versa. Note that you may need _
    to de-select and re-select the dimension before the graphics will update.
    
'Preconditions: dimensions are selected
    
'Note: IDimension2::DriveState does not work on 3D sketch dimensions. (SPR 369252)
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDispDim As SldWorks.DisplayDimension
Dim swDim As SldWorks.Dimension
Dim blnDriven As Boolean
Dim i As Integer
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)
        Set swDispDim = swSelMgr.GetSelectedObject6(i, -1)
        Set swDim = swDispDim.GetDimension2(Empty)
        If i = 1 Then
            If swDim.DrivenState = swDimensionDriven Then
                blnDriven = True
            Else
                blnDriven = False
            End If
        End If
        If blnDriven = False Then
            swDim.DrivenState = swDimensionDriven
        Else
            swDim.DrivenState = swDimensionDriving
        End If
    Next i
End Sub