Skip to content

Commit b038f71

Browse files
committed
Added the macro to set read-only state for all dimensions in the feature
1 parent aecb10a commit b038f71

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Const READ_ONLY As Boolean = True
2+
3+
Dim swApp As SldWorks.SldWorks
4+
Dim swModel As SldWorks.ModelDoc2
5+
6+
Sub main()
7+
8+
Set swApp = Application.SldWorks
9+
10+
Set swModel = swApp.ActiveDoc
11+
12+
Dim swSelMgr As SldWorks.SelectionMgr
13+
14+
Set swSelMgr = swModel.SelectionManager
15+
16+
Dim swFeat As SldWorks.Feature
17+
18+
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
19+
20+
If Not swFeat Is Nothing Then
21+
22+
Dim swDispDim As SldWorks.DisplayDimension
23+
24+
Set swDispDim = swFeat.GetFirstDisplayDimension
25+
26+
While Not swDispDim Is Nothing
27+
28+
Dim swDim As SldWorks.Dimension
29+
30+
Set swDim = swDispDim.GetDimension2(0)
31+
swDim.ReadOnly = READ_ONLY
32+
33+
Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
34+
35+
Wend
36+
37+
Else
38+
Err.Raise vbError, "", "Select feature"
39+
End If
40+
41+
End Sub
19.8 KB
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
caption: Set To Read-Only
3+
title: Macro to change read-only state of all dimensions of the selected feature in the SOLIDWORKS model
4+
description: VBA macro to change the read-only options for all dimensions of the selected feature of the active SOLIdWORKS model
5+
image: dimension-read-only.png
6+
---
7+
8+
![Dimension read-only property](dimension-read-only.png){ width=400 }
9+
10+
This SOLIDWORKS VBA macro changes the read-only state of all dimensions of the selected feature (e.g. sketch).
11+
12+
Set the target read-only state in the constant
13+
14+
~~~ vb
15+
Const READ_ONLY As Boolean = True 'True to set to Read-Only, False to remove Rea-Only flag
16+
~~~
17+
18+
{% code-snippet { file-name: Macro.vba } %}

0 commit comments

Comments
 (0)