Hide constraint names, keep other labels on connectors in Enterprise Architect

69 views Asked by At

I use Data modelling to model tables and their relations. The model displays the constraint names, which are often long and are unimportant to me. I want to display only cardinalities and join columns. Is there a way to hide the constraint names, and keep other labels?

I'm aware of the option to hide all connector labels, and the possibility to hide individual labels. The former is unusable (hides important information), the latter is impractical in large models.

Sample diagram

1

There are 1 answers

3
Oliv On

I managed to do it using the script below. I tested it in EA version 14.1 and 16.1 Corporate. To add the script, display the Scripting tab using *Ribbon > Specialize > Tools > Script Library *. Add a new diagram group, to which you can add a new VBScript:

enter image description here

Copy-paste the code below and then run the script.

option explicit

!INC Local Scripts.EAConstants-VBScript

' Script Name: LabelVisibility
' Author: Rupert Ryan (https://sparxsystems.com/forums/smf/index.php/topic,25631.msg250286.html#msg250286)
' Purpose: Changes label visibility across all diagram objects
' Date: 19/02/2018
'
Dim LLB 'Label Left (source) Bottom Source Role
Dim LLT 'Label Left (source) Top Source Multiplicity
Dim LMT 'Label Middle Top Name
Dim LMB 'Label Middle Bottom Stereotype
Dim LRT 'Label Right (dest) Top Dest Role
Dim LRB 'Label Right (dest) Bottom Dest Multiplicity
Dim IRHS 'Information Flows realized (dest)
Dim ILHS 'Information Flows realized (source)

LLB = 0
LLT = 1
LMT = 0
LMB = 1
LRT = 1
LRB = 0
IRHS = 1
ILHS = 1

dim geometryupdate
Dim hidden

Sub diagramconnector()
   Dim currentDiagram
   Set currentDiagram = repository.GetCurrentDiagram()
   Dim diagramlink
   Dim j
   Dim diagramlinks As EA.Collection
   Dim dirty
   dirty = false
   If currentDiagram.diagramlinks.Count > 0 Then
      For j = 0 To currentDiagram.diagramlinks.Count - 1
         Set diagramlink = currentDiagram.diagramlinks.GetAt(j)
         labellist (diagramlink.geometry)
         diagramlink.geometry = geometryupdate
         diagramlink.Update
         dirty = true
      Next
   End If
   if dirty then
      repository.ReloadDiagram currentDiagram.DiagramID
   end if
End Sub

Sub labellist(geometry)
   Dim strArray
   Dim intCount
   strArray = Split(geometry, ";")
   For intCount = LBound(strArray) To UBound(strArray)
   hidden = InStr(1, Trim(strArray(intCount)), "HDN")
      If Not hidden = 0 Then
         strArray(intCount) = labelhide(Trim(strArray(intCount)),hidden)
         geometryupdate = Join(strArray, ";")
      Else
      End If
   Next
End Sub

Function labelhide(label,hidden)
   Dim strArray
   Dim intCount
   strArray = Split(label, ":")
   Dim toggle
   toggle = Mid(label, hidden + 4, 1)
   Select Case Mid(strArray(0), 1, 4)
      Case "$LLB"
         toggle = LLB
      Case "LLT="
         toggle = LLT
      Case "LMT="
         toggle = LMT
      Case "LMB="
         toggle = LMB
      Case "LRT="
         toggle = LRT
      Case "LRB="
         toggle = LRB
      Case "IRHS"
         toggle = IRHS
      Case "ILHS"
         toggle = ILHS
   End Select
   labelhide = replace(label, Mid(label, hidden + 4, 1), toggle)
End Function

diagramconnector

Make sure you save your diagram before running the script, otherwise EA it will discard your unsaved changes. You also can't undo the effects of running the script (EA needs improving here, this is true for EA 16.1).