Author Topic: Creating Requirement using Script  (Read 2375 times)

Fabien

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Creating Requirement using Script
« 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:

Code: [Select]
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!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating Requirement using Script
« Reply #1 on: December 02, 2020, 10:50:42 pm »
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

Fabien

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Creating Requirement using Script
« Reply #2 on: December 02, 2020, 11:54:02 pm »
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:

Code: [Select]
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:
Code: [Select]
dim tag
set tag = e.TaggedValues.GetByName("id")
tag.Value("test")
tag.Update

Any ideas? Am I missing something?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Creating Requirement using Script
« Reply #3 on: December 03, 2020, 12:21:13 am »
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

Code: [Select]
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.

Fabien

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Creating Requirement using Script
« Reply #4 on: December 03, 2020, 02:50:15 am »
Geert,

I'll stay with your solution. It works.

Thanks again!