Some newbie questions: How did my flowchart get three kinds of master shapes, like
Database,
Database 1x1, and
Database 1x1.32? Why do some shapes have
Database for a master shape instead of
Database 1x1?
Database 1x1 is a master shape in the custom stencil I used. Why do some shapes have a number at the end of the master shape name?
Here are some of the master shape names for shapes on my flowchart.
- Data
- Data 1x1
- Database
- Database 1x1
- Database 1x1.32
- Decision
- Decision 1x1
- Decision 1x1.36
- Process
- Process 1x1
- Process 1x1.29
- Start/End 1x1
It's not part of the question, but here is the code I used to print the master shape names.
Sub PrintTheMasterShapeNameOfEveryShape() 'General use
Dim lng As Long, lngCount As Long
Dim shp As Visio.Shape, str As String
ActiveWindow.SelectAll
lngCount = ActiveWindow.Selection.Count
For lng = 1 To lngCount
Set shp = ActiveWindow.Selection(lng)
If Not shp.Master Is Nothing Then
str = shp.Master.Name
If str <> "Dynamic connector" Then Debug.Print str
End If
Next lng
End Sub
When a master is edited, Visio updates a date-time stamp (that we don't have access to).
It compares these stamps when a master is dragged into a drawing. So if you drag a modified "Decision" from a stencil into a drawing that already has a "Decision" master (in it's Document Stencil - every drawing has this internal stencil), then Visio thinks; "These 'Decision' masters are not the same, because they have different stamps". Therefore Visio appends an index to differentiate them.
If you are working on shapes and testing them in a drawing, you will quickly make a very large file that has many versions of the "same" master.
For this reason, I develop shapes in the Document Stencil of the drawing that I use for testing and development. It is easier to keep one version of each master, and make changes to that.
At some point down the line, you can decide that you're done developing, the put the masters into a stand-alone stencil for distribution.
Thank you for the tip about using master shapes from the Document Stencil. Please tell me whether you see any problems with the next steps I did. Was it okay to replace master shapes in the flowchart, or is it better to start over?
I wrote and ran a macro to replace master shapes. For example, shapes with Process 1x1 and Process 1x1.29 for a master shape were changed to Process for a master shape.
Sub ReplaceTheMasterShapeOfSomeShapes()
'Shared at http://visguy.com/vgforum/index.php?topic=8938
Dim lng As Long, lngCount As Long
Dim objShape As Visio.Shape, strFile As String
Dim strPart As String, strFull As String
strFile = ActiveDocument.FullName
ActiveWindow.SelectAll
lngCount = ActiveWindow.Selection.Count
If lngCount = 0 Then Exit Sub
On Error GoTo PrintID
'Selects a shape (and continues if it has a master shape).
For lng = 1 To lngCount
Set objShape = ActiveWindow.Selection(lng)
If Not objShape.Master Is Nothing Then
'Saves the beginning and the full name of the master shape.
strPart = Left(objShape.Master.Name & " ", 5)
strFull = objShape.Master.Name
'If the beginning is recognized but the full name isn't,
' then changes the master shape.
If strPart = "Data " And strFull <> "Data" Then
objShape.ReplaceShape _
Documents.Item(strFile).Masters.Item("Data")
ElseIf strPart = "Datab" And strFull <> "Database" Then
objShape.ReplaceShape _
Documents.Item(strFile).Masters.Item("Database")
ElseIf strPart = "Decis" And strFull <> "Decision" Then
objShape.ReplaceShape _
Documents.Item(strFile).Masters.Item("Decision")
ElseIf strPart = "Docum" And strFull <> "Document" Then
objShape.ReplaceShape _
Documents.Item(strFile).Masters.Item("Document")
ElseIf strPart = "Proce" And strFull <> "Process" Then
objShape.ReplaceShape _
Documents.Item(strFile).Masters.Item("Process")
ElseIf strPart = "Start" And strFull <> "Start/End" Then
objShape.ReplaceShape _
Documents.Item(strFile).Masters.Item("Start/End")
End If
GoTo NoAction
PrintID:
Debug.Print objShape.ID
NoAction:
End If
Next lng
ActiveWindow.DeselectAll
End Sub
Next I ran the CleanMe macro from https://blog.bvisual.net/2015/01/07/cleaning-visio-documents/ (https://blog.bvisual.net/2015/01/07/cleaning-visio-documents/) to delete the unused master shapes.
Then I noticed shape names that were based on deleted master shapes, such as Process 1x1.122. I wrote and ran a macro to change shape names to the current master shape and current shape ID.
Sub RenameShapesWithMasterShapeAndID()
'Shared at http://visguy.com/vgforum/index.php?topic=8938
Dim lng As Long, lngCount As Long
Dim objShape As Visio.Shape
'Selects every shape.
ActiveWindow.SelectAll
lngCount = ActiveWindow.Selection.Count
If lngCount = 0 Then Exit Sub
On Error GoTo PrintID
'Loops through every shape.
For lng = 1 To lngCount
Set objShape = ActiveWindow.Selection(lng)
If Not objShape.Master Is Nothing Then
With objShape
.Name = .Master & "." & .ID 'Renames a shape.
End With
GoTo NoAction
PrintID:
Debug.Print objShape.ID
NoAction:
End If
Next lng
ActiveWindow.DeselectAll
End Sub