How to modify specific Attribute Display font/colour in macro

I have a macro that sets the colour, font etc of Entities based on Attachment Bindings.

However, I also want to do the same for specific attributes, based on attachment bindings on each attribute.

I know how to loop through attributes on an entity, but I don't know how to access an 'AttributeDisplay' object, or whatever it is called.

I don't have any user manual for this kind of thing, and end up just looking through example macros.

So, does anyone know how I can access the equivalent of 'AttributeDisplay' objects of an EntityDisplay object?

thanks!


David

  • This macro will do what you ask:
    Just change the RGB values to make the attribute your desired color


    'MACRO TITLE: AUTO-COLOR ALL Attributes WITH Attachments MACRO
    'This macro will make all attributes with attachments purple. 'First select those entities you wish to apply this to. 'This macro illustrates how to use entity objects, attribute objects, and selected objects - and how to distinguish among them. '------------------------------------------------------------------ Sub Main Dim MyDiagram As Diagram Dim MyModel As Model Dim MyEntityDisplay As EntityDisplay Dim MyEntity As Entity Dim MySubModel As SubModel Dim MyAttribute As AttributeObj Dim MySelObject As SelectedObject Dim Attachment_ct As Integer Dim ObjectName As String Dim Logical As Boolean 'Get the current diagram. Set MyDiagram = DiagramManager.ActiveDiagram 'Get the current model. Set MyModel = MyDiagram.ActiveModel 'Determine if the model is logical or physical. Logical = MyModel.Logical 'Get the current submodel. Set MySubModel = MyModel.ActiveSubModel 'Now, we iterate through all the selected entities in 'the submodel and set the entity background color of 'selected entities with foreign keys to red. For Each MySelObject In MySubModel.SelectedObjects 'Get the object type - we are only concerned with entities. ObjType = MySelObject.Type If ObjType = 1 Then ' Get the ID for the selected object. ID = MySelObject.ID ' Now get the actual entity object with this ID. ' The model contains the collection of all the entities. Set MyEntity = MyModel.Entities.Item(ID) 'We need to the name of the entity. We can use the 'name to get the entity display object from the submodel. If Logical = True Then ' If the model is logical, get the entity ' name. ObjectName = MyEntity.EntityName Else ' If the model is physical, get the table name. ObjectName = MyEntity.TableName End If 'Iterate through all the attributes in the entity 'and see if there are any that have attachments. For Each MyAttribute In MyEntity.Attributes 'Determine if the attribute has attachments. Attachment_ct = MyAttribute.BoundAttachments().Count If Attachment_ct > 0 Then 'change the color and font weight of the attribute if it has at least one attachment Set MyAttribute.Color = RGB(128, 0, 225) Set MyAttribute.Font.Bold = True If Logical = True Then ' If the model is logical, get the entity ' name. ObjectName = MyEntity.EntityName Else ' If the model is physical, get the table name. ObjectName = MyEntity.TableName End If Else 'If the attribute doesn't have an attachment, make it black with normal font weight Set MyAttribute.Color = RGB(0, 0, 0) Set MyAttribute.Font.Bold = False End If Next MyAttribute End If Next MySelObject End Sub