powerdesigner

How to programmatically change the color of a column in a PowerDesigner 16 PDM diagram


I can use VBA to loop through the columns of a table and change many properties related to the Column object itself. What I am looking for is to change the color of select columns of a table as displayed in a PDM diagram. It is possible to do this from the UI, by clicking on a column of a table to select it in a diagram, then right-click to display a context menu, then select 'Sub-Objects Format'.


Solution

  • Here is an example, which does that with some arbitrary criteria to write in red some Columns in a Physical Data Model, when their name contains a "b"... using the ObjectCompositeSymbol.SubObjects attribute.

    option explicit
    const workfont = "Arial,8,N,255,0,0"
    dim diags: set diags = createobject("Scripting.Dictionary")
    dim m : set m = activemodel
    dim t
    for each t in m.tables
       ' public name of subobjects: Column; 0: display all
       dim sb : sb = "Column 0" + vbcrlf
       dim c,some : some = false
       for each c in t.columns
          ' our criteria is: column name contains a b
          dim match : match = instr(lcase(c.name),"b") <> 0
          if match then
             sb = sb + "{"+ c.GetAttribute("ObjectID")+"} " + workfont + vbcrlf
             some = true
          end if
       next
       if not some then sb = ""
       ' apply subobjects coloring
       dim s
       for each s in t.symbols
          if s.subobjects <> sb then
             s.subobjects = sb
             if not diags.exists(s.diagram) then diags.add s.diagram,0
          end if
       next
    next
    if diags.count > 0 then
       dim d
       for each d in diags.keys
          output "... redraw "+d.name
          d.RedrawAllViews
       next
    end if
    

    Result after script execution