Files
Traverse body features and make dimensions read-only
Code
'This macro demonstrates two different approaches to traverse all body features in order to make _
all feature dimensions read-only
'Precondtions: part is open
'Results:
'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 swSelMgr As SldWorks.SelectionMgr
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swModel.FirstFeature
'According to the remarks for IFeature::GetFirstDisplayDimension, the feature dimensions _
must first be made visible
swModel.Extension.SetUserPreferenceToggle swDisplayFeatureDimensions, swDetailingNoOptionSpecified, True
Do While Not swFeat Is Nothing
'METHOD 1 - determine if the selected object is of type swSelBODYFEATURES, which corresponds _
to any feature that creates or modifies a body
swFeat.Select2 False, 0
If swSelMgr.GetSelectedObjectType3(1, -1) = swSelBODYFEATURES Then
Call MakeReadOnly(swFeat)
End If
'METHOD 2 - determine if the current feature has any faces; if so then it must be a body feature
'If swFeat.GetFaceCount <> 0 Then
' Call MakeReadOnly(swFeat)
'End If
Set swFeat = swFeat.GetNextFeature
Loop
swModel.Extension.SetUserPreferenceToggle swDisplayFeatureDimensions, swDetailingNoOptionSpecified, False
End Sub
Sub MakeReadOnly(swFeat As SldWorks.Feature)
Dim swDispDim As SldWorks.DisplayDimension
Dim swDim As SldWorks.Dimension
Set swDispDim = swFeat.GetFirstDisplayDimension
Do While Not swDispDim Is Nothing
Set swDim = swDispDim.GetDimension2(Empty)
swDim.ReadOnly = True
'Note that an automation error will occur if you try to use IDisplayDimension::GetNext5
Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
Loop
End Sub