-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_connection_points_in_selected_shape
116 lines (76 loc) · 3.81 KB
/
delete_connection_points_in_selected_shape
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
Sub delete_connection_points_in_selected_shape()
'
' Delete *all* connection points in the currently selected Shape and it's subshapes.
'
' based on http://visguy.com/vgforum/index.php?topic=3955.0
' and https://books.google.de/books?id=rDlrCwAAQBAJ&pg=PA340
'
Dim selShape As Visio.Shape
Dim colShpResult As Collection
Dim i As Integer
Set colShpResult = New Collection
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
Set selShape = ActiveWindow.Selection.PrimaryItem
Call GetShapesInShape(selShape, iRecursionDepth - 1, colShpResult)
If MsgBox("Delete all Connection Points in this Shape?", 4, "Delete in this Shape?") = vbYes Then
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Clear")
If selShape.SectionExists(visSectionConnectionPts, False) = True Then
For i = 0 To selShape.Section(visSectionConnectionPts).Count
selShape.DeleteRow visSectionConnectionPts, 0
Next
End If
Application.EndUndoScope UndoScopeID1, True
End If
If MsgBox("Delete all Connection Points in Subshapes?", 4, "Delete in Subshapes?") = vbYes Then
Dim UndoScopeID2 As Long
UndoScopeID2 = Application.BeginUndoScope("Clear")
For Each subShape In colShpResult
If subShape.SectionExists(visSectionConnectionPts, False) = True Then
For i = 0 To subShape.Section(visSectionConnectionPts).Count
subShape.DeleteRow visSectionConnectionPts, 0
Next
End If
Next subShape
Application.EndUndoScope UndoScopeID2, True
End If
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
Public Function GetShapesInShape(shp As Visio.Shape, _
Optional iRecursionDepth As Integer = -1, _
Optional colShpResult As Collection = Nothing _
) As Collection
' Abstract: Get sub-shapes of a shape using depth-first traversal.
' Parameters:
' * shp: the shape which need to be processed.
' * iRecursionDepth: the max depth of sub-shapes to return.
' 0 means count only top level shapes; sub-shapes are ignored.
' -1 means count top level shapes and all sub-shapes.
' * colShpResult: is only used internally by this procedure.
' Immediate: Call PrintVisioObjects(GetShapesInShape(ActiveWindow.Selection(1)))
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'// initialize colShpResult if this has not been done already
If colShpResult Is Nothing Then
Set colShpResult = New Collection
End If
'// do few checks first
If shp Is Nothing Then GoTo PROCEDURE_END
'// iterate through sub-shapes of shp
Dim shpSub As Visio.Shape
For Each shpSub In shp.Shapes
'// add shpSub to our result
Call colShpResult.Add(shpSub)
'// check there are children for shpSub and recursion should continue
If shpSub.Shapes.Count > 0 And iRecursionDepth <> 0 Then
'// go recursively to get sub-shapes of shpSub
Call GetShapesInShape(shpSub, iRecursionDepth - 1, colShpResult)
End If
Next shpSub
PROCEDURE_END:
'// return whatever been collected
Set GetShapesInShape = colShpResult
End Function