Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: EAButNotForGames on July 16, 2024, 09:35:47 pm

Title: Creating a Custom Table via Script
Post by: EAButNotForGames on July 16, 2024, 09:35:47 pm
Moin,

Does anybody know if I can create a Custom Table with the dimensions x an y via a script.
I can create a dimensionless table. But not with rows and columns.
I figured, I need to set the TaggedValues data and dataFormat, but I can't change them via script.
Title: Re: Creating a Custom Table via Script
Post by: Geert Bellekens on July 16, 2024, 10:01:59 pm
Why can't you change them with a script?

Can you show the code you are using?

Geert
Title: Re: Creating a Custom Table via Script
Post by: EAButNotForGames on July 17, 2024, 03:32:58 pm
So the code is basically:

Code: [Select]
var new_element as EA.Collection;
new_element = selectedPackage.Elements;

new_element = new_element.AddNew("A Table", "Custom Table");
new_element.TaggedValuesEx.GetAt(0).Notes = "Something"                    //This is the TaggedValue: data ->
new_element.TaggedValuesEx.GetAt(1).Notes = "Also Something"             //This is the TaggedValue: dataFormat -> They both have a specific format, but I was to lazy to type it

new_element.Update();

I tried both Value and Notes for TaggedValue and TaggedValueEx and it didn't work. 
Title: Re: Creating a Custom Table via Script
Post by: Geert Bellekens on July 17, 2024, 04:07:05 pm
You have to first get the tagged value object, then update it's value, and then save it to the database with .Update()

Element.Update() only saves the properties of the element to the database, not the properties of your tagged values.

Also, after creating an element you need to Update() it before it will have the tagged values you need.
And you'll want to create an element using the fully qualified stereotype. So something like "EAUML::Custom Table", making sure the stereotype exactly corresponds to the defined stereotype, inclusing upper/lower case.

Geert
Title: Re: Creating a Custom Table via Script
Post by: EAButNotForGames on July 17, 2024, 09:10:24 pm
Thank you very much!
This was such a simple mistake.

Also, do you by chance know, how I can access the Inital Value of a property?
Title: Re: Creating a Custom Table via Script
Post by: Geert Bellekens on July 17, 2024, 09:18:12 pm
Also, do you by chance know, how I can access the Inital Value of a property?
You can't really. That value is defined in the MDG, and not stored in the database.

Geert
Title: Re: Creating a Custom Table via Script
Post by: EAButNotForGames on July 17, 2024, 10:10:26 pm
Ah, dam.