我使用数据建模来对表及其关系进行建模。模型显示约束名称,这些名称通常很长并且对我来说并不重要。我只想显示基数并连接列。有没有办法隐藏约束名称并保留其他标签?
我知道隐藏所有连接器标签的选项以及隐藏单个标签的可能性。前者不可用(隐藏重要信息),后者在大型模型中不切实际。
我设法使用下面的脚本来做到这一点。它适用于 EA 16.1。要添加脚本,请使用 *功能区 > 专业化 > 工具 > 脚本库 * 显示脚本选项卡。添加一个新的图表组,您可以向其中添加新的 VBScript:
复制粘贴下面的代码,然后运行脚本。
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
确保在运行脚本之前保存图表,否则 EA 将丢弃您未保存的更改。您也无法撤消运行脚本的效果(EA 需要改进,对于 EA 16.1 来说是这样)。