Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Maggie on April 20, 2012, 01:15:43 am
-
Hi
Within my addin I am trying to find all the base classes for a given class.
so far I have
foreach (EA.Connector connector in element.Connectors)
{
if (connector.Type == "Generalization")
{
EA.Element clientElement = Repository.GetElementByID(connector.ClientID);
}
}
This gives me a list of all Generalization connectors, including classes that derive from the target class.
What I need is only the classes from which the target class in derived.
I would be grateful if someone could give me some pointers
Thanks
Maggie
-
Hi,
Check SupplierEnd, ClientEnd properties of the connectors (not sure which one actually) to filter out those connected on the 'right' end.
HTH
Günther
-
you can se this method.
public static ArrayList getBaseClasses(EA.Element classToGet, ArrayList returnList)
{
EA.Element actClass = classToGet;
returnList.Add(actClass);
foreach (EA.Element actBaseClass in actClass.BaseClasses)
{
returnList = getBaseClasses(actBaseClass, returnList);
}
return returnList;
}
to use this method:
ArrayList classAndParents = getBaseClasses(classToFindParents, new ArrayList());
-
Thanks!
-
My implementation is at https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/ElementWrapper.cs basically the same:
/// EA provides a shortcut tot the superclasses through its
/// element.BaseClasses
/// Normally we would get those via the element.generalizations.general
public HashSet<UML.Classes.Kernel.Class> superClasses {
get {
return new HashSet<UML.Classes.Kernel.Class>
(this.model.factory.createElements(this.wrappedElement.BaseClasses)
.Cast<UML.Classes.Kernel.Class>());
}
set { throw new NotImplementedException(); }
}