Macro to change read-only state of all dimensions of the selected feature in the SOLIDWORKS model
This SOLIDWORKS VBA macro changes the read-only state of all dimensions of the selected feature (e.g. sketch).
Set the target read-only state in the constant
Const READ_ONLY As Boolean = True 'True to set to Read-Only, False to remove Rea-Only flag
Const READ_ONLY As Boolean = True Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Dim swSelMgr As SldWorks.SelectionMgr Set swSelMgr = swModel.SelectionManager Dim swFeat As SldWorks.Feature Set swFeat = swSelMgr.GetSelectedObject6(1, -1) If Not swFeat Is Nothing Then Dim swDispDim As SldWorks.DisplayDimension Set swDispDim = swFeat.GetFirstDisplayDimension While Not swDispDim Is Nothing Dim swDim As SldWorks.Dimension Set swDim = swDispDim.GetDimension2(0) swDim.ReadOnly = READ_ONLY Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim) Wend Else Err.Raise vbError, "", "Select feature" End If End Sub