Change Entity color based on attachment binding value

Hi All,

I have been struggling to figure this out, request your expertise please? I need to change the entity color based on the value present in one of the attachment bindings in the entity. I am struggling to loop through the entities and checking the value in attachment bindings. Would you mind sharing any of your ideas/code snippets pls?

Below is the example:

Let us say I have two entities Employee, Manager. I have added multiple attachment bindings to these entities - lets say Department, Band.  Wherever Department = "IT", I want to change that enity color to purple. Can you pls guide?

Thanks in advance.


  • Hi Sandy,

    Sorry for the late answer but if you still need it, I have updated the sample macro named Auto-Color All Entities with FKs.bas to replace the FK verification by the attachment Department=IT.

      Dim MyAttachment As BoundAttachment
                'Iterate through all the attachments for the entity
                'and see if there is one Department=IT.
                For Each MyAttachment In MyEntity.BoundAttachments
                    'Determine if the entity has an attachment Department=IT
                    If (MyAttachment.Attachment.Name = "Department") And MyAttachment.ValueCurrent = "IT" Then
                        'If the attachment name is Department & its value is IT, then we want
                        'to get the entity display object from the
                        'submodel and make the entity display object
                        'In order to get the entity display object from
                        'the submodel, we pass in the entity name to the
                        'EntityDisplays 'Item' function.
                        'Note: We cannot pass in the ID of the entity object
                        'because entity display objects and entity objects
                        'use different sets of IDs.
                        If Logical = True Then
                            ' If the model is logical, get the entity 
                            ' name.
                            ObjectName = MyEntity.EntityName
                            ' If the model is physical, get the table 
                            ' name.
                            ObjectName = MyEntity.TableName
                        End If
                        Set MyEntityDisplay = MySubModel.EntityDisplays.Item(ObjectName)
                        'Change the color of local, non-key attributes.
                        'We want the color to be purple.
                        'Each of the three primary colors can have a 
                        'value from 0-255.
                        'using the RGB function we can mix blue and red
                        'to make purple
                        MyEntityDisplay.BackgroundColor = RGB(255, 0, 255)
                        Exit For        
                    End If
                Next MyAttachment



    Macro available here.