Book a Demo

Author Topic: Constraints and Connectors  (Read 5160 times)

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Constraints and Connectors
« on: June 17, 2015, 01:28:53 am »
Hello !

I would need some help : I have an activity diagram with connectors, and constraints linked to some connectors.

I am using a C# script which is supposed to parse my model and finally reach the constraint and give me his name and attributes for a specific connector.

This is what my code looks like for now (simplified) :

Code: [Select]
for each Diagram in Package
    for each Element in Diagram
        for each Connector in Element
            for each Constraint in Connector

In the User Guide, Constraint does exist in the Connector class, but I am getting an error from E.A. when I am trying to get all the constraints from my connectors.

I have also been trying the other way, starting from the constraint and wanting to reach the connector :

Code: [Select]
for each Diagram in Package
    for each Element in Diagram
        if Element.type = Constraint
        ***and there is my Problem, i don't know what links the connector and the constraint***

There is a link between the two but it'is not another connector and i don't know what it's, maybe can you answer my question or help me out ?

I hope I have been clear enough about my issue, if not, feel free to tell me so I'll explain better.

Thanks !

P.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Constraints and Connectors
« Reply #1 on: June 17, 2015, 02:06:46 am »
Not sure about your (pseudo?) code but from Diagram you can only retrieve DiagramObjects and from there you need to get the ElementID to retrieve the real element via Repository.GetElementByID. This allows to check the type for Constraint.

q.

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Constraints and Connectors
« Reply #2 on: June 17, 2015, 06:37:27 pm »
Yes Qwerty, my bad.

But there is a Problem in this code and  I don't know why, it seems like it's impossible for me to get the connectors constraints with this code since I have an error :

Code: [Select]
foreach (EA.DiagramObject theDiagramObject in theDiagram.DiagramObjects)
{      
    EA.Element e = Repository.GetElementByID(theDiagramObject.ElementID);
    foreach (EA.Connector theConnector in e.Connectors)
    {
         foreach (EA.Constraint theConstraint in theConnector.Constraints)
         {
            MessageBox.Show("Name : " + theConstraint.Name +  " Value = " + theConstraint.Notes);                  
         }
    }
}

The error occurs in the foreach (EA.Constraint theConstraint in theConnector.Constraints). When I finally reach a connector's constraint. with the following text :

Unable to cast COM object of type 'System._ComObject' to interface type 'EA.Constraint'. This operation failed because the QueryInterface call on the COM complenent for the interface with IID '{There is a long ID number}' failed du to the following error : No such interface supported.
 
So how can I bypass this and finally get all the Constraints linked to my Connectors ?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Constraints and Connectors
« Reply #3 on: June 17, 2015, 08:37:43 pm »
Try this:
Code: [Select]
foreach (EA.DiagramObject theDiagramObject in theDiagram.DiagramObjects)
{      
   EA.Element e = Repository.GetElementByID(theDiagramObject.ElementID);
   foreach (EA.Connector theConnector in e.Connectors)
   {
        foreach (EA.ConnectorConstraint theConstraint in theConnector.Constraints)
        {
           MessageBox.Show("Name : " + theConstraint.Name +  " Value = " + theConstraint.Notes);                  
        }
   }
}

But I don't think that will give you what you need. I guess you are looking for constraint elements (looks like a note) linked to a connector. This will give you the constraints ON the connector.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Constraints and Connectors
« Reply #4 on: June 17, 2015, 09:02:42 pm »
To clarify this: you have a connector and a constraint element linked with a [highlight]connector link[/highlight]?

q.

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Constraints and Connectors
« Reply #5 on: June 17, 2015, 09:29:47 pm »
With a NoteLink i guess.

Sorry i cannot upload  an image from my work my company does no allow any picturehosting websites  :-/

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Constraints and Connectors
« Reply #6 on: June 17, 2015, 09:31:22 pm »
Quote
Try this:
Code: [Select]
foreach (EA.DiagramObject theDiagramObject in theDiagram.DiagramObjects)
{      
   EA.Element e = Repository.GetElementByID(theDiagramObject.ElementID);
   foreach (EA.Connector theConnector in e.Connectors)
   {
        foreach (EA.ConnectorConstraint theConstraint in theConnector.Constraints)
        {
           MessageBox.Show("Name : " + theConstraint.Name +  " Value = " + theConstraint.Notes);                  
        }
   }
}

But I don't think that will give you what you need. I guess you are looking for constraint elements (looks like a note) linked to a connector. This will give you the constraints ON the connector.

Geert

Yes this is exactly what I want ! My constraint is linked to a connector by a NoteLink (?)
« Last Edit: June 17, 2015, 09:35:03 pm by Piqcked »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Constraints and Connectors
« Reply #7 on: June 17, 2015, 09:51:02 pm »
Sure. I meant NoteLink (connected to a connector). So Geert's answer is what you were after.

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: Constraints and Connectors
« Reply #8 on: June 18, 2015, 03:13:07 am »
Quote
Sure. I meant NoteLink (connected to a connector). So Geert's answer is what you were after.

q.
No I don't think so. All I did was replace the wrong EA.Constraint with the correct EA.ConnectorConstraint.

You'll have to do something like:
Code: [Select]
foreach (EA.DiagramObject theDiagramObject in theDiagram.DiagramObjects)
{      
  EA.Element e = Repository.GetElementByID(theDiagramObject.ElementID);
  if (e.Type == "Constraint")
  {
        foreach (EA.Connector theConnector in e.Connectors)
        {
            if (theConnector.Type == "NoteLink")
            {
                  int constrConnectorID = //TODO: figure out how to get the constrainted connector ID from the Notelink as I don't remember exactly. Probably hidden somewhere in a style field or something
                  EA.Connector constraintedConnector = Repository.GetConnectorByID(constrConnectorID)
                  //now do something useful with the constraintedConnector
            }
        }
  }
}

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Constraints and Connectors
« Reply #9 on: June 18, 2015, 06:06:28 am »
Ah lol. I thought you got the right turn. Now I suppose this it the right one  :D

The Constraint (/Note) element has PDATA4
Code: [Select]
idref=<connectorId>;

q.
« Last Edit: June 18, 2015, 06:10:16 am by qwerty »

Piqcked

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Constraints and Connectors
« Reply #10 on: June 23, 2015, 11:39:43 pm »
Sorry for the late answer but thank you both !