Book a Demo

Author Topic: Updating Links in Diagram based on StereoType  (Read 3980 times)

DanaNuch

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Updating Links in Diagram based on StereoType
« on: December 02, 2011, 08:15:39 am »
I am working on building a script with the automated interface to be able to update the color of a link on the diagram between two elements base on the StereoType I have assigned.  

For example:  System A connects to System B with a link that is marked "enhance"  I want to change the line color to be RED.

I have tried many different ways and think I am either missing something or maybe a bug.  I think the former is more the case... so I am posting here hoping someone can point out the mistake I made.  

Here is the sample code... I took out a lot of the complexity but left the core pieces.  

// Interface colors Colors
var iENHANCE      = "enhance";
var ienhanceColor        = "BCol=65535;BFol=0;LCol=65535;LWth=1;";
function ColorDiagramInterfaceBasedOnStereoType()
{
    Repository.EnsureOutputVisible( "Script" );
    
    Session.Output( "Update Diagram  Interfaces based on Stereo Types" );
    Session.Output( "=========================================" );
    
    // Get the type of element selected in the Project Browser
    var treeSelectedType = Repository.GetTreeSelectedItemType();
    
    // Handling Code
            var theDiagram as EA.Diagram;
            theDiagram = Repository.GetTreeSelectedObject();

            // Get all diagramLinks for this diagram
            var diagramLinks as EA.Collection;
            diagramLinks = theDiagram.DiagramLinks;
            var currentLink as EA.DiagramLink
            var correspondingLink as EA.Connector;  
            var levCode;
            for ( var i = 0 ; i < diagramLinks.Count; i++ ) {
                  // Get the current diagram link
               currentLink = diagramLinks.GetAt(i);
               correspondingLink = Repository.GetConnectorByID(currentLink.ConnectorID)
               switch (correspondingLink.Stereotype)  {
                              
            case iENHANCE: {
                  currentLink.Style = ienhanceColor;
                  currentLink.Update;
                              break;
                              }
                   
                }
                                    
      }
                  
}


Hope this make sense what I am trying to do.  The issue is when I set these attributes for the currentLink.Style they show up in the Model, but not on the Diagram and are not visible as the right colors or widths.  

Thanks,

Dana

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updating Links in Diagram based on StereoType
« Reply #1 on: December 02, 2011, 06:24:07 pm »
Dana,

What do you mean with "they show up in the model"?
Have you tried to reload the diagram after updating the diagramLinks?

Geert

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: Updating Links in Diagram based on StereoType
« Reply #2 on: December 02, 2011, 09:07:31 pm »
Rather than using a script, have you considered creating your stereotyped line as a profile and then attaching a shapescript for the line which would draw in the colour of your choice? You even have different colours depending upon a tagged value setting

This profile could then be wrapped up in an MDG which would load everytime EA  is loaded.

The use of your stereotype would fire off the shapescript and hence you would have a coloured line.

The process of profiles, shapescripts and MDG is very well documented in the user guide

Cheers

Phil

Models are great!
Correct models are even greater!

DanaNuch

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Updating Links in Diagram based on StereoType
« Reply #3 on: December 03, 2011, 01:35:18 am »
Quote
Dana,

What do you mean with "they show up in the model"?
Have you tried to reload the diagram after updating the diagramLinks?

Geert


Geert,  I am able to retreive the data from the Links the next time I run the script.  So I know they are writen to EA Database.  They are just not showing up on the Pictures.  

DanaNuch

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Updating Links in Diagram based on StereoType
« Reply #4 on: December 03, 2011, 01:43:13 am »
Phil,
Quote
Rather than using a script, have you considered creating your stereotyped line as a profile and then attaching a shapescript for the line which would draw in the colour of your choice? You even have different colours depending upon a tagged value setting

This profile could then be wrapped up in an MDG which would load everytime EA  is loaded.

The use of your stereotype would fire off the shapescript and hence you would have a coloured line.

The process of profiles, shapescripts and MDG is very well documented in the user guide

Cheers

Phil


This is a great option... I have not tried process of profiles, shapescripts and MDG .... Just something I can check out as well.

The purpose of coloring the diagram and not using StereoType to drive the coloring is I have multiple diagrams I need to show with the same objects/links.  I want the diagram colored for SteroTypes on one diagram and then I color it for Tagged Values on another.  But the two are not shown on the same diagram.

Thanks for the alternate suggestions.

Dana