Book a Demo

Author Topic: DiagramLinks getting the source and targets?  (Read 10439 times)

Barrie Treloar

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
DiagramLinks getting the source and targets?
« on: February 16, 2017, 05:59:51 pm »
DiagramLinks says
SourceInstanceUID : String - Returns the Unique Identifier of the source object.
TargetInstanceUID : String - Returns the Unique Identifier of the target object.

And when debugging the script I printed out some IDs and GUIDs
selectedElement id = 505 guid={EB58D0E1-1B80-4db2-AAD4-C2CBBC3B5C0C}   
diagramLink ConnectorID=458 SourceInstanceUID=859B351F   

Looking at the UID output... what's that?

There is nothing in Repository to get something by UID, only by Guid or ID.
Repository.GetElementByGuid
Repository.GetElementByID

I'm trying to write a script that takes selected elements and then to change the line style of the element's connectors.
SelectedObjects returns DiagramObjects which only knows about the Element via ElementID, it doesn't know anything about the connectors.

From Repository.GetCurrentDiagram.SelectedObjects and locating the element via Repository.GetElementByID(selectedObject.ElementID) I can get at the Connectors but not the DiagramLinks for those connectors.

Iterating over Repository.GetCurrentDiagram.DiagramLinks gives me SourceInstanceUID and TargetInstanceUID but as noted above those values dont appear useful. I can check whether the DiagramLinks.ConnectorID is in the selectedElement.Connectors Collection, but this seems rather roundabout.

So, should I be using UIDs?
Is there a more direct what than all the indirection I have mentioned.


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: DiagramLinks getting the source and targets?
« Reply #1 on: February 16, 2017, 06:47:00 pm »
Those UIDs (which are not GUIDs) have a rare and mostly EA-internal use. What you need to change is the Style in diagramLinks.

When you inspect the connector style you will eventually find something like

Quote
Mode=<mode>;EOID=<xid>;SOID=<xid>;Color=<col>;LWidth=<width>;TREE=<tree>;

a semi-colon separated list of line attributes. The single parameters have the following meaning:

<mode>:
1 = Direct
2 = Auto Route
3 = Custom
8 = Bezier

Do not try to set other numeric values here. A value of 7 makes the connector appear as a strange note link.

<tree>:
OR = Orthogonal Round
OS = Orthogonal Square
LH = Lateral Horizontal LV = Lateral Vertical
V = Tree Style Vertical
H = Tree Style Horizontal

<col> is a color value and <width> is a line width numeric value.

I have not the faintest idea what <xid> means. Neither for EOID nor for SOID. The best is to ignore
these values and to not supply them when setting the connector style.

(from my Scripting book)

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramLinks getting the source and targets?
« Reply #2 on: February 16, 2017, 09:29:55 pm »
In cases like that I usually use an SQL query to get the id's I need, and based on those id's I get my objects.

That is usually much much faster then iterating over connectors and diagramLinks etc...

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: DiagramLinks getting the source and targets?
« Reply #3 on: February 16, 2017, 09:40:12 pm »
Geert is right. If you issue
Code: [Select]
Repository.SQLQuery("SELECT * FROM t_diagramlinks WHERE ConnectorID=<theId>")you will get the diagram(s) where the connector is used.

q.

Barrie Treloar

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: DiagramLinks getting the source and targets?
« Reply #4 on: February 16, 2017, 10:11:11 pm »
Thanks for the replies.

qwerty,

setting
DiagramLink.LineStyle = 7
works fine.
This must do the black magic behind the scenes as the resultant .Style is
DiagramLink.Style = Mode=3;EOID=7502739F;SOID=859B351F;Color=-1;LWidth=0;TREE=LH;   

Geert,
Have you got some thoughts one how to get those IDs?
The diagram is never very large, nor are the number of connectors on an element very large, so the speed penalty of a scan is not great.
Rather it's just a tedious indirect process.

I have the selected object, but I can't get at its DiagramLinks easily to make the adjustments.

qwerty,
With the SQL I can get the row I want, then I need to use the black magic to mangle the style back in, and then Repository.Execute to put it back.
I'll need to think about that some more.
The indirect scan is solving my problem well enough now without introducing this complexity.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramLinks getting the source and targets?
« Reply #5 on: February 16, 2017, 11:02:38 pm »
There's no getDiagramLinkByID, so you'll have no choice but to loop the diagram.Diagramlinks

But you can get the connectorID's using SQL, which avoids having to loop all connectors of all selected objects.

So first you make a comma separated list of all selected objectID's

and then use something like the following to get the connectorID's

Code: [Select]
select c.Connector_ID from t_connector c
inner join t_diagramlinks dl on dl.ConnectorID = c.Connector_ID
where
(c.Start_Object_ID in (objectIDs) or c.End_Object_ID in (objectIDs))
and dl.DiagramID = currentDiagramID

Then loop the DiagramLinks and select those where the ID is in the list retrieved this way.

But that is only needed if the normal "iterating" way is getting too slow (which is often the case for any non trivial model)

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: DiagramLinks getting the source and targets?
« Reply #6 on: February 17, 2017, 02:14:08 am »
It might be sufficient to just supply diagramLinks.Style with the appropriate part (e.g. "Mode=3") and EA will do what's necessary. If that won't work (that is, EA will loose the other style info) you need to do some string manipulation.

q.