Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Fabien on December 02, 2020, 09:07:59 pm
-
Hi,
I'm developing a script to import requirements from an Excel sheet (with EA Version 15). I am able to create new requirements in a package and assign the SysML::requirement profile to them by using this code snippet:
dim e as EA.Element
set e = spec.Elements.AddNew("Requirement1", "Requirement")
e.StereotypeEx = "SysML1.4::requirement"
e.Update
But I cannot figure out how to set the id property of the newly created requirement. I tried using the Properties Attribute of the Element class as specified in the object reference model, but I failed...
Has anyone ever succeeded to automatically access element properties using a script? Is it possible?
Thanks for your help!
-
Fabien,
What ID property are you talking about?
You can access the internal elementID and elementGUId directly on the element, but those are readonly and are set by EA.
There's a good chance you'll find what you need in the tagged values.
Geert
-
Hi Geert,
I was talking about the id properties as visible in the Properties view (under the group "Requirement (from SysML 1.5)").
Thank you for pointing the tagged value out to me. I am now able to set the id using this:
for count = 0 to e.TaggedValues.Count - 1
set tag = e.TaggedValues.GetAt(count)
if tag.Name = "id" then
tag.Value("test")
tag.Update
end if
next
But this simpler code does not work:
dim tag
set tag = e.TaggedValues.GetByName("id")
tag.Value("test")
tag.Update
Any ideas? Am I missing something?
-
I never use the GetByName() operations.
In the case of the tagged values, I'm not even sure if there are multiple tagged values with the same name. If that is the case the GetByName will probably return one of them, but in no defined order.
the first looks ok, but I usually do a foreach
for each tag in e.TaggedValues
if tag.Name = "id" then
tag.Value = "test"
tag.Update
end if
next
Geert
PS. I'm not sure what the tag.Value("test") does. I would expect it to return an error.
-
Geert,
I'll stay with your solution. It works.
Thanks again!