Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: QuimSA on June 26, 2019, 08:05:01 pm
-
Hi folks
I have to apply the same 2 constraints to a whole collection of interfaces and i'm wondering if there's a way to automatically do so by scripting. I've been searching and i'm not sure it's possible.
I'm thinking it should be possible using the 'Constraint class' method: Update(). But i dont know how
https://sparxsystems.com/enterprise_architect_user_guide/14.0/automation/constraint.html
I appreciate any help!
Thanks
P.D. By the way this is my first post in this forum, hi everyone!!! :D :D
-
Hi Quim,
Creating new stuff in EA via the API is done using the EA.Collection.AddNew() method.
This is the same for elements in a package
Package.Elements.AddNew("MyClass", "Class")
attributes
Element.Attributes.AddNew("myAttribute","string")
or constraints
Element.Constraints.AddNew("MyConstraint","invariant")
This method returns the new object.
After creating it make sure you Update() it or it won't be saved to the database.
You can search my github repositories for examples
- https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library (https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library)
- https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework (https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework)
Geert
-
Thanks geert!
Finished it already, if someone is interested, it looks like this:
var theElement as EA.Element; //Inicialization of Enterprise Architect element
function CreateConstraints(interf){//-------------------------------CREATES CONSTRAINTS----------------------------------
newConstraint = interf.Constraints.AddNew("",""); //enter here desired constarint name and type
newConstraint.Update();
newConstraint = null;
Session.Output("Successfully created constraint @: " + interf.Name);
}
function Main(){
theElement = Repository.GetTreeSelectedObject(); //Gets the object selected in project browser
var portCounter = theElement.Elements.Count;
for(j=0;j<portCounter;j++){
if(theElement.Elements.GetAt(j).Stereotype == "AUTOSAR Sender Receiver Port"){
CreateConstraints(theElement.Elements.GetAt(j));
Session.Output("Done");
}
}
}
-
Oops. Thanks for the flowers, but it was Geert answering your question ;-)
q.
-
Oops haha
fixed