Search code examples
enterprise-architect

Working with elements "diagram properties" in script


I have an my own MDG, consist of several elements. I need change view of those elements when its placed at different diagram. There is a mechanism called "user-selected settings" in MDG and I use its to change view of elements (e.g. via shape script function "HasProp" ). But for several reason I need to change diagram property for element via script. Are there any way to work with diagram property for element within script ?


Solution

  • It's possible but a bit tricky. First of all you need to get hold of the right diagram's table data stored in t_diagram. Issue a SQL like

    SELECT StyleEx FROM t_diagram WHERE Diagram_ID = <theID>
    

    Of course <theID> must be the diagram id of the diagram. Now you can use some string operations. Here's what my test diagram brought:

    ExcludeRTF=0;DocAll=0;HideQuals=0;AttPkg=1;ShowTests=0;ShowMaint=0;SuppressFOC=1;MatrixActive=0;SwimlanesActive=1;KanbanActive=0;MatrixLineWidth=1;MatrixLineClr=0;MatrixLocked=0;TConnectorNotation=UML 2.1;TExplicitNavigability=0;AdvancedElementProps=1;AdvancedFeatureProps=1;AdvancedConnectorProps=1;m_bElementClassifier=1;ProfileData=;MDGDgm=VW VA Functional 3::Use case activity;STBLDgm=;ShowNotes=0;OPTIONS_9CEFE070=Structure=1:;VisibleAttributeDetail=0;ShowOpRetType=1;SuppressBrackets=0;SuppConnectorLabels=0;PrintPageHeadFoot=0;ShowAsList=0;SuppressedCompartments=;Theme=:119;SaveTag=79E21B13;;

    which is a CSV at its best. See the

    OPTIONS_9CEFE070=Structure=1:;
    

    which actually encodes the diagram properties. Here it's just one with the name Structure and its value is set to 1. The 9CEFE070 refers to the GUID the diagram object. Of course not directly.

    So find the diagram objects of the diagram itself with

    SELECT Object_ID, ObjectStyle FROM t_diagramobjects
    

    The Object_ID is for identifying the object behind (you might use a join to get needed information). And the ObjectStlye contains something like (from my test)

    DUID=9CEFE070;HideIcon=0;
    

    And there you have that hex string. Now you know that this one object has a diagram property set.

    You should issue some queries manually to get familiar with that.

    Now, to set a property, you "just" have to find the DUID from the diagram object of the diagram (just use the query above). Now you can add that OPTIONS_<duid> part or in case it already exists you need to modify it with according string operations. Finally you need to update the diagram table with

    Repository.Execute("UPDATE t_diagram SET StyleEx = `<new string>` WHERE diagram_id = <theID>")
    

    Note that this is an undocumented operation and you get

    a) no support and b) can easily clobber your whole model which is c) the reason for a).

    Have a backup!