Skip to content

Commit 000680c

Browse files
author
artem
committed
Updated clear revision table macro to process all drawings
1 parent 1b6193f commit 000680c

File tree

2 files changed

+97
-28
lines changed

2 files changed

+97
-28
lines changed
Lines changed: 76 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,74 @@
1+
Const ALL_DRAWINGS As Boolean = False
2+
3+
Const INITIAL_REV As String = "001"
4+
Dim COLUMNS As Variant
5+
16
Dim swApp As SldWorks.SldWorks
2-
Dim swDraw As SldWorks.DrawingDoc
3-
Dim swSheet As SldWorks.Sheet
47

58
Sub main()
69

10+
'Fill the revision table columns
11+
COLUMNS = Array("Sample Zone", "", "Description", "", "Admin")
12+
713
Set swApp = Application.SldWorks
814

9-
Set swDraw = swApp.ActiveDoc
10-
11-
If Not swDraw Is Nothing Then
12-
13-
Set swSheet = swDraw.GetCurrentSheet
14-
15-
Dim swRevTable As SldWorks.RevisionTableAnnotation
15+
Dim swDraw As SldWorks.DrawingDoc
1616

17-
Set swRevTable = swSheet.RevisionTable
17+
If ALL_DRAWINGS Then
1818

19-
If Not swRevTable Is Nothing Then
20-
21-
ClearRevisionTable swRevTable
22-
23-
AddRevision swRevTable, "001", Array("Sample Zone", "", "Description", "", "Admin")
19+
Dim vDocs As Variant
20+
vDocs = swApp.GetDocuments
21+
22+
Dim i As Integer
23+
24+
For i = 0 To UBound(vDocs)
25+
If TypeOf vDocs(i) Is SldWorks.DrawingDoc Then
26+
Set swDraw = vDocs(i)
27+
Debug.Print "Processing " & swDraw.GetTitle()
28+
ProcessDrawing swDraw
29+
End If
30+
Next
31+
32+
Else
2433

34+
Set swDraw = swApp.ActiveDoc
35+
36+
If Not swDraw Is Nothing Then
37+
38+
ProcessDrawing swDraw
39+
2540
Else
26-
MsgBox "There is no revision table in the drawing"
41+
Err.Raise vbError, "", "Drawing is not open"
2742
End If
43+
44+
End If
2845

46+
47+
End Sub
48+
49+
Sub ProcessDrawing(draw As SldWorks.DrawingDoc)
50+
51+
Dim vSheets As Variant
52+
vSheets = draw.GetSheetNames
53+
54+
Dim swSheet As SldWorks.sheet
55+
Set swSheet = draw.sheet(CStr(vSheets(0)))
56+
57+
Dim swRevTable As SldWorks.RevisionTableAnnotation
58+
59+
Set swRevTable = swSheet.RevisionTable
60+
61+
If Not swRevTable Is Nothing Then
62+
63+
ClearRevisionTable swRevTable
64+
65+
AddRevision swRevTable, INITIAL_REV, COLUMNS
66+
67+
draw.SetSaveFlag
68+
2969
Else
30-
MsgBox "Plase open the drawing"
70+
'NOTE: API will not work with the revision tables on any but first sheet
71+
Err.Raise vbError, "", "No revision table is found on the first sheet of" & draw.GetTitle
3172
End If
3273

3374
End Sub
@@ -46,14 +87,17 @@ Sub ClearRevisionTable(swRevTable As SldWorks.RevisionTableAnnotation)
4687
revId = swRevTable.GetIdForRowNumber(i)
4788

4889
If revId <> 0 Then
49-
swRevTable.DeleteRevision revId, True
90+
91+
If False = swRevTable.DeleteRevision(revId, True) Then
92+
Err.Raise vbError, "", "Failed to delete revision"
93+
End If
5094
End If
5195

5296
Next
5397

5498
End Sub
5599

56-
Sub AddRevision(swRevTable As SldWorks.RevisionTableAnnotation, revName As String, rowData As Variant)
100+
Function AddRevision(swRevTable As SldWorks.RevisionTableAnnotation, revName As String, rowData As Variant) As Boolean
57101

58102
Dim i As Integer
59103
Dim swTableAnn As SldWorks.TableAnnotation
@@ -67,14 +111,19 @@ Sub AddRevision(swRevTable As SldWorks.RevisionTableAnnotation, revName As Strin
67111

68112
rowIndex = swRevTable.GetRowNumberForId(revId)
69113

70-
For i = 0 To UBound(rowData)
114+
If rowIndex <> -1 Then
115+
For i = 0 To UBound(rowData)
116+
117+
If rowData(i) <> "" Then
71118

72-
If rowData(i) <> "" Then
119+
swTableAnn.Text(rowIndex, i) = rowData(i)
73120

74-
swTableAnn.Text(rowIndex, i) = rowData(i)
75-
76-
End If
77-
78-
Next
121+
End If
122+
123+
Next
124+
AddRevision = True
125+
Else
126+
AddRevision = False
127+
End If
79128

80-
End Sub
129+
End Function

solidworks-api/document/drawing/clear-revision-table-new-revision/index.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@ This example finds the revision table and removes all revisions and then adds ne
1111

1212
![Revision Table](sw-revision-table.png){ width=640 }
1313

14+
Set the name of the revision in the **INITIAL_REV** constant
15+
16+
~~~ vb
17+
Const INITIAL_REV As String = "A" 'create new revision A
18+
~~~
19+
20+
Fill the values of the revision table columns in the **COLUMNS** variable. use an empty string **""** to keep the default value (e.g. date or revision)
21+
22+
~~~ vb
23+
COLUMNS = Array("First Column Value", "", "Third Column Value", "", "Fifth Column Value") 'Fill the 1st, 3rd and 5th columns with the values and keep 2nd and 4th columns default value
24+
~~~
25+
26+
In order to process all open drawings, instead of the active drawing, set the **ALL_DRAWINGS** constant to **True**
27+
28+
~~~ vb
29+
Const ALL_DRAWINGS As Boolean = True 'process all open drawings
30+
~~~
31+
1432
[IRevisionTableAnnotation](https://help.solidworks.com/2018/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.irevisiontableannotation.html) SOLIDWORKS API interface is used to manage specific functionality of this type of the table.
1533

16-
{% code-snippet { file-name: Macro.vba } %}
34+
> Only revisions table on the first sheet are supported
35+
36+
{% code-snippet { file-name: Macro.vba } %}

0 commit comments

Comments
 (0)