Book a Demo

Author Topic: Adding an Attribute via scripting whose Type is a selected element  (Read 3425 times)

pianoman

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
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!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Adding an Attribute via scripting whose Type is a selected element
« Reply #1 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.

pianoman

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Adding an Attribute via scripting whose Type is a selected element
« Reply #2 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