Colour Code Alternate Keys in Logical data model

Hi All,

Good day!

I have logical data model and I want to highlight the alternate keys in all of my entities in a different colour. I tried using the format -> Colors -> "Unique Indexes" and changed the colour. However, it doesn't change the colour of the alternate keys.

Any leads on how to highlight alternate keys on the logical data model?


  • Hi,

    I don't know how to automatically update the color for all the AK, but you can change the display of your Entities to show when it's an alternate key:

    I hope this helps.


  • You can use a macro to color them.

    You can try this one:

    ' This macro will make all entities with alternate keys purple.
    Const MyColor As Long = VbColors.vbMagenta ' RGB(255, 0, 255)
    Sub Main
    	Dim MyDiagram As Diagram
    	Dim MyModel As Model
    	Dim MySubModel As SubModel
    	Dim MyEntityDisplay As EntityDisplay
    	Dim MyEntity As Entity
    	Dim MyIndex As Index
    	Dim ObjectName As String
    	Dim EntitiesWithAKs As Integer
    	' Initialize 
    	EntitiesWithAKs = 0
    	' Get the current diagram.
    	Set MyDiagram = DiagramManager.ActiveDiagram
    	' Get the current model.
    	Set MyModel = MyDiagram.ActiveModel
    	' Get the current submodel.
    	Set MySubModel = MyModel.ActiveSubModel
    	' Iterate through all the entity display objects in the 
    	' current SubModel And Check if their indexes include
    	' Alternate Keys.
    	For Each MyEntityDisplay In MySubModel.EntityDisplays
    		' In order to get a reference to the actual entity object,
    		' we get the name of the entity from the entity
    		' display object, and then pass it to the 'Item' method
    		' of the Entities collection.  This will allow us to get
    		' the actual entity object.
    		ObjectName = MyEntityDisplay.Name
    		Set MyEntity = MyModel.Entities.Item(ObjectName)
    		Debug.Print "Entity: " & ObjectName
    		' Iterate through all the indexes in the entity
    		' and see if there is at least one alternate key.
    		For Each MyIndex In MyEntity.Indexes
    			Debug.Print MyIndex.KeyType; Chr(9); MyIndex.Name
    			If MyIndex.KeyType = "A" Then
    				' Change the color of the Entity Display Object
    				MyEntityDisplay.BackgroundColor = MyColor
    				EntitiesWithAKs = EntitiesWithAKs + 1
    				' Skip the next indexes of the current entity
    				Exit For
    			End If
    	Next MyEntityDisplay
    	Debug.Print "# Entities with AKs: "; EntitiesWithAKs
    	MsgBox "# Entities with AKs: " & EntitiesWithAKs, vbInformation, "Entities with AKs"
    End Sub