Book a Demo

Author Topic: VBScript: Adding TaggedValue when creating a signal  (Read 3858 times)

game

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
VBScript: Adding TaggedValue when creating a signal
« on: March 17, 2020, 01:21:09 am »
Hello,

thanks to the forum I have now managed to make a VB script where a signal is created.

Now I would like to add 5 TaggedValues to this element and change the color to pink.

Are there code examples for TaggedValues here? I found something in the EAScriptLib, but I can't really handle it.

Here is my code so far:

Code: [Select]
case otPackage
' Code for when a package is selected

dim thePackage as EA.Diagram
set thePackage = Repository.GetTreeSelectedObject()
dim theElement as EA.Element

set theElement = thePackage.Elements.AddNew("Fehlernummer", "Signal")

theElement.Update()
thePackage.Elements.Refresh()

Best regards

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBScript: Adding TaggedValue when creating a signal
« Reply #1 on: March 17, 2020, 02:00:00 am »
Creating new stuff works pretty much the same way for all things.
You have to call the AddNew() operation on the collection.

In this case

Code: [Select]
theElement.TaggedValues.AddNew("tagName", "value")
You can find a bunch of example scripts here: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library

Geert

game

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: VBScript: Adding TaggedValue when creating a signal
« Reply #2 on: March 17, 2020, 09:40:36 pm »
Hello,
thanks for the answer.

A TaggedValue is now created when the element is created.
But with the second one I get the following error:


Code: [Select]
case otPackage
' Code for when a package is selected

dim thePackage as EA.Diagram
set thePackage = Repository.GetTreeSelectedObject()
dim theElement as EA.Element
'dim theElement as EA.TaggedValue

set theElement = thePackage.Elements.AddNew("Errornumber", "Signal")
set theElement = theElement.TaggedValues.AddNew("Tag 1", "Description Tag 1")
set theElement = theElement.TaggedValues.AddNew("Tag 2", "Description Tag 2")

What's my mistake here?
I've tried it without a set, but it's not working either.

I have looked at the examples, but they are also very complex :-)

Is there a simple way to assign a sterotype to the signal which already exists, so that the element takes over this formatting?

Many greetings

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBScript: Adding TaggedValue when creating a signal
« Reply #3 on: March 17, 2020, 10:25:27 pm »
The problem is that you are using the same variable for your element and for your new tagged value.

After the first tagged value creation your theElement variable contains an instance of the new tagged value, and no longer an instance of the element.
You are trying to add your second taggedValue on the first tagged value, and since tagged values don't have a property called TaggedValues, you get an error.

Yes, you can assign a stereotype to an element. Use StereotypeEx to assign a fully qualified stereotype (something like "BPMN2::Activity")

Geert

game

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: VBScript: Adding TaggedValue when creating a signal
« Reply #4 on: March 18, 2020, 03:13:37 am »
Thanks for the help.

I have now managed to assign the tags and the stereotype.
I think currently this is enough for me.

Thanks for the support.

Many greetings