Book a Demo

Author Topic: Need scripting documentation  (Read 4368 times)

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Need scripting documentation
« on: October 28, 2020, 12:41:50 pm »
I need to find documentation for scripting.  I am trying to deal with database tables, and the EA.Element object does not seem to offer a way to get a casted pointer (a typed variable pointer) that would expose and allow me to alter attributes specific to database table columns and database table constraints.

I did find documentation of Index > Automation > Scripting (https://www.sparxsystems.com/enterprise_architect_user_guide/15.2/automation/the_scripter_window.html).  But this does not have any link to a reference section that has the documentation that I want for the following.



1)  Where do I find documentation that lists the objects and attributes I need, to check whether each table column is part of the primary key, and if so, to change the sequence/order of the table columns so that the PK columns are at the top/front of the table?

2) I want to check all foreign key constraints, and check whether an index with a similar name already exists on the table.  If the matching index is not found, then I want to create the index. 
Where can I find documentation for accessing the foreign key constraints and indexes on database tables in a script?  And documentation to create an index?

3)  I want to check if two standard columns (for audit purposes) already exist on the database table.  If not, then create these columns.  Where can I find documentation for viewing the current collection of columns, and to create new columns?


I would really appreciate the specific URL to the EA help page that shows these database attributes. 
Thank you.

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Need scripting documentation
« Reply #1 on: October 28, 2020, 12:47:10 pm »
For clarity:  I am wanting to create a script, in the Scripting pane.  Such as creating a new Diagram Group script.  I already have a sample script that processes each selected object in the diagram and outputs the name and type.

I would prefer not to have to write something in another language and then use the API to dig into EA.  But if you think that is the best way to go, feel free to suggest why scripting is not workable/wise.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Need scripting documentation
« Reply #2 on: October 28, 2020, 04:01:00 pm »

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Need scripting documentation
« Reply #3 on: October 29, 2020, 03:19:09 pm »
Thank you Geert.  I had previously found that webpage, but the Index for it does not seem to list all pages for the various classes.  I have now found the typical/generic class information; thanks.


I still do not know where to go to find special information for modelled database tables.  Note that I am not looking for information on the EA schema that shows the tables in an EA repository.  Instead, I want to model my own custom database tables in EA, and then alter the Foreign Keys and Columns on those custom database tables from within a script in EA.

I found some table column information:  After I set a variable of type EA.Element to point to my modelled table, I can use myElement.Attributes or myElement.AttributesEx collections.

But how do I view the list of Foreign Keys on the database table?  I want to be able to read these Foreign Keys and create Indexes.  Note that the Constraints and ConstraintsEx collections in the EA.Element object are not correct; for my database table, both these collections had Count=0, but my database table has two Foreign Keys.

Thank you.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Need scripting documentation
« Reply #4 on: October 29, 2020, 03:54:49 pm »
You're after the
Code: [Select]
Methods collection.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Need scripting documentation
« Reply #5 on: October 29, 2020, 04:08:49 pm »
A foreign key is actually stored in EA as a combination of both an operation (stereotype FK) EA.method and an association

This class might give you an idea of what to look for: https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/Databases/ForeignKey.cs

Geert

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Need scripting documentation
« Reply #6 on: October 30, 2020, 10:29:23 am »
Thank you Geert and Eve.  Geert, I'll have a look at your code sample, thank you.