Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: pianoman on November 21, 2019, 05:44:28 am

Title: Adding an Attribute via scripting whose Type is a selected element
Post by: pianoman on November 21, 2019, 05:44:28 am
Hello All,

I'm trying to add multiple attributes to a selected object. I am wondering if the Sparx Automation Interface / Object Model allows for the addition of an attribute whose Type is a selected element as one would normally do by selecting "Select Type..." in the Type dropdown menu in the Attributes section of an object. I've got the below script, but I'm trying do understand what I can put in the "Type" field that I've left blank in the code below to reference to a selected element.

Code: [Select]
dim element AS EA.Element
dim pack AS EA.Package
dim att AS EA.Attribute

set pack = Repository.GetTreeSelectedPackage()
set element = pack.Elements.AddNew("TestElm", "Class")
set att = element.Attributes.AddNew("TestAtt", "")
att.Update
element.Attributes.Refresh
pack.Elements.Refresh

Appreciate any guidance!
Title: Re: Adding an Attribute via scripting whose Type is a selected element
Post by: qwerty on November 21, 2019, 05:58:36 am
It's just the classifier to be set:

attr.classifier = element.elementid

(how ever that VB syntax needs to be for that)

q.
Title: Re: Adding an Attribute via scripting whose Type is a selected element
Post by: pianoman on November 22, 2019, 04:48:19 am
Thanks qwerty,

I was getting confused since selecting an element from the drop down "Select Type..." accomplished assigning a ClassifierID and Type on the t_attribute table in the back end. So I had to use the

att.ClassifierID = someelement.ElementID
AND
att.Type = someelement.Name