Book a Demo

Author Topic: Adding a set of attributes to a large number of elements  (Read 7177 times)

Bulent

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Adding a set of attributes to a large number of elements
« on: September 06, 2017, 12:52:36 am »
Is there a quick way of adding the same set of attributes to a large number of elements?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a set of attributes to a large number of elements
« Reply #1 on: September 06, 2017, 05:47:37 am »
No. EA still is not OO in many respects. The only way is to write a script (which is fairly easy).

q.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Adding a set of attributes to a large number of elements
« Reply #2 on: September 06, 2017, 10:39:22 am »
Is there a quick way of adding the same set of attributes to a large number of elements?
You can drag a set of attributes from the browser of one element to another element on a diagram (thereby adding a copy to the destination).  However, if you have VERY many that's still tedious.

Paolo

Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1405
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Re: Adding a set of attributes to a large number of elements
« Reply #3 on: September 06, 2017, 06:18:59 pm »
Here is a suggested script to create the same attributes on the classes within the selected package. It can be improved to loop through the subpackages, only update classes with a given criteria such as a tagged value, etc.

Code: [Select]
option explicit
!INC Local Scripts.EAConstants-VBScript   
'
' Script Name: Populate attributes (package script)
' Author: Guillaume[at]umlchannel.com
' Purpose: Create the same set of attributes on each class within the selected package
' Date: 6/09/2017

sub OnProjectBrowserScript()
' Get the type of element selected in the Project Browser
dim treeSelectedType
treeSelectedType = Repository.GetTreeSelectedItemType()
select case treeSelectedType'
case otPackage
dim thePackage as EA.Package
set thePackage = Repository.GetTreeSelectedObject()
dim allObjects as EA.Collection
dim currentElement
set allObjects = thePackage.Elements
dim i
for i = 0 to allObjects.Count - 1
set currentElement = allObjects.GetAt( i )
if currentElement.Type = "Class" then
addAttribute currentElement, "attr1"
addAttribute currentElement, "attr2"
addAttribute currentElement, "attr3"
end if
next
case else
' Error message
Session.Prompt "This script does not support items of this type.", promptOK
end select
end sub

sub addAttribute(ClassToProcess, attributeName)
dim attributes as EA.Collection
set attributes = ClassToProcess.Attributes
dim newAttribute as EA.Attribute
set newAttribute = attributes.AddNew( attributeName, "" )
newAttribute.Update()
attributes.Refresh()
end sub

OnProjectBrowserScript

Hope it helps.
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com