Book a Demo

Author Topic: Automating Expose Interface  (Read 2884 times)

ramhog69

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Automating Expose Interface
« on: October 17, 2008, 05:00:08 am »
I am trying to Expose an interface on a component through automation.  

I create a new element with a type of "Component" named newElement.
I create a new element with a type of "Interface" named newInterface

Then I make a call to newElement.EmbeddedElements.AddNew(name of new interface, "ProvidedInterface").  The Provided Interface is in the model but it is not linked to the original interface.  I should be able to add a new Operation to the Interface Component, then create a message to that operation on a sequence diagram.  But the new operation doesn't show up.  I can do this through the EA UI, but Automation isn't working.  Please help me understand what I am missing in automation to make this work.

I have tried calling Update() and Refresh() after creating each element, but that doesn't change anything.

Thank you.
Kalvin

ramhog69

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Automating Expose Interface
« Reply #1 on: October 22, 2008, 02:34:49 am »
I am posting the answer to my question for anyone else that runs into this.  It was provided to me by Sparx support people.

This is the answer to the problem of Expose Interface through creating a ProvidedInterface in automation.

This code will get access to an existing interface and the component that will expose that interface.
Then, create the Exposed interface.
Finally, update the changes to the model.

Code: [Select]

// Get references to existing elements
EA.IDualElement mainComponent = (EA.IDualElement)package.Elements.GetByName("MainComponent");
EA.IDualElement componentElement = (EA.IDualElement)package.Elements.GetByName("NewComponentToExposeInterfaceOn");
EA.IDualElement baseInterface = (EA.IDualElement)mainComponent.Elements.GetByName("BaseInterface");

// Create new interface
EA.Element newExposedInterface = (EA.Element)componentElement.Elements.AddNew("NewInterfaceName", "ProvidedInterface");
newExposedInterface.ClassfierID = baseInterface.ElementID;

// Update changes
componentElement.Update();
newExposedInterface.Update();