Book a Demo

Author Topic: Add existing interface on a port  (Read 5393 times)

The apprentice

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Add existing interface on a port
« on: October 15, 2018, 07:46:19 pm »
Hi,

I would like add an existing interface on my port. I tried this :
Code: [Select]
var oto = (EA.Element)port1.EmbeddedElements.AddNew("", "RequiredPort");
oto.ElementID = poto.ElementID;


But ElementID is an attribute read only. Do you a have solutions?

Thank you

Arshad

  • EA User
  • **
  • Posts: 291
  • Karma: +21/-1
    • View Profile
Re: Add existing interface on a port
« Reply #1 on: October 15, 2018, 11:23:39 pm »
Hi

Please follow the below code snippet. It will add existing Port to the Interface in diagram.


Code: [Select]
//Parent Element ( Interface )
var element as EA.Element;
element = Repository.GetTreeSelectedObject();
//Get the created Port element ( It should be under the parent element )
var portEle as EA.Element;
portEle = Repository.GetElementByID();




// Diagram under which the elemets available
var diag as EA.Diagram;
diag = Repository.GetDiagramByID(1963);
var diagCollection as EA.Collection;
diagCollection = diag.DiagramObjects;



var DiagObj as EA.DiagramObject;
DiagObj = diagCollection.AddNew("", "");
        DiagObj.ElementID = portEle.ElementID;
        DiagObj.Update();
   
diag.Update();

Repository.ReloadDiagram(diag.DiagramID);




HTH
Arshad

The apprentice

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Add existing interface on a port
« Reply #2 on: October 16, 2018, 07:09:03 pm »
Hi

I wanted the opposite. Add existing Interface to the port in diagram.

Thank's to :

Code: [Select]
EA.Element interface = (EA.Element)currentPackage.Elements.GetByName("IMyMBD");// I use GetByName just for the example
         int potoid = interface.ElementID;
         EA.Element port2 = (EA.Element)currentElement.Elements.GetByName("Port2");
         EA.Element inter = (EA.Element)port2.Elements.AddNew("", "RequiredInterface");
         inter.ClassfierID = potoid;
         inter.Update();
         inter.Refresh();

it works.

Thank you

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Add existing interface on a port
« Reply #3 on: October 16, 2018, 07:30:23 pm »
You are not adding it to any diagram in the sample. You'd need to add to diagram.diagramObjects. I'd guess you don't need to supply coordinates for interfaces since they are at fixed locations inside ports anyway. So basically Arshad is exactly telling what you need to do.

q.

The apprentice

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Add existing interface on a port
« Reply #4 on: October 16, 2018, 09:10:46 pm »
So I don't understand, I work on Diagram component.

My Component has a port (child Element). I need to add Required/Provided interface existing on the port ( new child element of the port).

This my code :

Code: [Select]

EA.Diagram curentDiagram; // Diagram wich contains my component.
EA.Element currentElement; // My component.
EA.Element Elport; // My port.
EA.Element myInterface;

EA.Element myInterface = (EA.Element)currentPackage.Elements.GetByName("IMyMBD");
var DiagObj = (EA.DiagramObject)currentDiagram.DiagramObjects.AddNew("", "");
DiagObj.ElementID = port2.ElementID;
DiagObj.Update(); // this triggers an error : System.Runtime.InteropServices.COMException


I wish to illustrate what I want. How to use IMG tag ?
Thank for your time.

Arshad

  • EA User
  • **
  • Posts: 291
  • Karma: +21/-1
    • View Profile
Re: Add existing interface on a port
« Reply #5 on: October 16, 2018, 09:15:33 pm »
You should not add a new diagram object . instead try the below code

Code: [Select]


EA.Diagram curentDiagram; // Diagram wich contains my component.
EA.Element currentElement; // My component.
EA.Element Elport; // My port.
EA.Element myInterface;

EA.Element myInterface = (EA.Element)currentPackage.Elements.GetByName("IMyMBD");

        var diagCollection as EA.Collection;
     diagCollection = currentDiagram.DiagramObjects;



var DiagObj as EA.DiagramObject;
     DiagObj = diagCollection.AddNew("", "");
        DiagObj.ElementID = Elport.ElementID;
        DiagObj.Update();
   
currentDiagram.Update();

Repository.ReloadDiagram(currentDiagram.DiagramID);
 



I hope Elport is a child element of  myInterface.


HTH
Arshad

The apprentice

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Add existing interface on a port
« Reply #6 on: October 16, 2018, 09:52:46 pm »
I have the same error :

Code: [Select]
//EA.Element currentElement; // My component.
//EA.Element Elport; // My port.
//EA.Element myInterface;
EA.Element Elport = (EA.Element)currentElement.Elements.GetByName("Port2");
EA.Element myInterface = (EA.Element)currentPackage.Elements.GetByName("IMyMBD");
EA.Collection  diagCollection = (EA.Collection)currentDiagram.DiagramObjects;
EA.DiagramObject  DiagObj = (EA.DiagramObject)diagCollection.AddNew("", "Interface");
DiagObj.ElementID = Elport.ElementID;
DiagObj.Update();// triggers error
   
eARepository.ReloadDiagram(currentDiagram.DiagramID);

In my case My interface should be the child of the port.

edit :

I understood the importance of DiagramObject and it works for adding ports on my component. But when I try to add an interface like this :
Code: [Select]
EA.Element item =  (EA.Element)newPort1.EmbeddedElements.AddNew("", "ProvidedInterface");
            item.Update(); 
            var diagramItem = (EA.DiagramObject)currentCmpDiagram.DiagramObjects.AddNew("", "");
            diagramItem.ElementID = item.ElementID;
            diagramItem.Update();
            newPort1.Update();
            currentCmpDiagram.Update();
            currentPackage.Update();
            eARepository.ReloadDiagram(currentCmpDiagram.DiagramID);

digramItem.Update() triggers an execption of type System.StackOverFlowExecption. What's the problem here ?
Thank you
« Last Edit: October 17, 2018, 07:01:30 pm by The apprentice »