Author Topic: Using ChatGPT to create EA Scripts  (Read 5382 times)

Ian Mitchell

  • EA User
  • **
  • Posts: 506
  • Karma: +22/-4
  • The eaDocX and Model Expert guy
    • View Profile
Using ChatGPT to create EA Scripts
« on: March 14, 2023, 08:08:00 pm »
(Dated March 2023)
I've just had a go at getting ChatGPT to create some simple EA Scripts for me - and they work fairly well.
For VBScripts it didn't understand OptionExplicit, but apart from that, the script ran correctly.
This should be really useful for users who are new to EA: just let the chatbot do the hard work, and refine it's results.
Not sure how it would perform for really complex scripts, but for simple utilites this may be the way forward.

All I need to do now is to plug the output from ChatGPT directly into the scripting engine and we have a natural-language query mechanism.
Ian Mitchell, Designer, eaDocX


www.eaDocX.com
www.theartfulmodeller.com

PeteC

  • EA User
  • **
  • Posts: 91
  • Karma: +1/-0
    • View Profile
Re: Using ChatGPT to create EA Scripts
« Reply #1 on: March 15, 2023, 10:10:07 pm »
Out of interest, what was your input (i.e. how detailed) to generate a script?
Did you specify that it was to be a script for EA or just ask it for a VB/J/Javascript?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13402
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Using ChatGPT to create EA Scripts
« Reply #2 on: March 15, 2023, 10:13:36 pm »
I'm not convinced it will be useful for beginners.

The problem is that it won't be perfect. So it will almost work.  But going from almost there to works is probably even harder for a beginner than writing the whole thing from scratch.

Geert

Ian Mitchell

  • EA User
  • **
  • Posts: 506
  • Karma: +22/-4
  • The eaDocX and Model Expert guy
    • View Profile
Re: Using ChatGPT to create EA Scripts
« Reply #3 on: March 16, 2023, 01:21:30 am »
I think I asked it:
"write a Sparx Enterprise Architect vbscript to change a tagged value of an element in a diagram, and refresh the diagram" .

The code I get from this did, as Geert predicted, have a small error:

Calling the subroutine declared the types of the parameters:
Sub ChangeTaggedValue (element As EA.Element, tagName As String, newValue As String)

..instead of the style EA needs:
Sub ChangeTaggedValue (element , tagName , newValue )

Apart from that, the structure, the use of the EA API, declaring of variables and the overall structure all worked OK.
I agree that I would not in any way guarantee that such a piece of generated code would always work, but I still think it saves a lot of typing for the expert, and a lot of researching for the beginner.

Please add to this post of you have any other experiences - good or bad - with this mechanism of using EA. I still think it's a really useful tool in our EA tool bag.
Ian Mitchell, Designer, eaDocX


www.eaDocX.com
www.theartfulmodeller.com

adamPL

  • EA Novice
  • *
  • Posts: 6
  • Karma: +1/-0
    • View Profile
Re: Using ChatGPT to create EA Scripts
« Reply #4 on: March 16, 2023, 08:43:07 pm »
Neat idea! I'm going to try for myself

I suppose that making "simple" scripts is very handy for anyone, who has some experience in scripting, but does not have extensive knowledge of EA capabilities. Then, with documentation and experience, user can refine the script if needed.

Barrie Treloar

  • EA User
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: Using ChatGPT to create EA Scripts
« Reply #5 on: March 20, 2023, 04:01:08 pm »
The problem is that documentation is difficult to come by.
EA makes some odd choices as you traverse down its internal object model, and is missing some functions/methods that would seem obvious.

Coming from someone who doesn't know VBScript but can code in other languages there are quite a few gotchas that really blocked me from making any progress.

Purely for my own benefit for when I come back to scripting in EA in a few years time, I've added to Geert's VBScript-Library with Documentation:
https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/tree/master/Documentation

His repository of scripts give me the major benefit that I can use the EA Automation Reference https://www.sparxsystems.com/enterprise_architect_user_guide/15.2/automation/reference.html to find what I want to use and grep for example of its use.

Richard Freggi

  • EA User
  • **
  • Posts: 493
  • Karma: +18/-7
    • View Profile
Re: Using ChatGPT to create EA Scripts
« Reply #6 on: March 23, 2023, 03:49:14 pm »
So I tried ChatGPT and I literally have chills in my spine.  Honestly my hair is standing on end.

Here's the full conversation (this is about my other posts about changing database type in an EA model).  What do you guys thing and is the script good to run on EA 16.1?

Code: [Select]
write a Sparx system architect script to change the database type for tables within a selected package, including all subpackages
To change the database type for tables within a selected package and all of its subpackages in Sparx System Architect, you can use the following script:

vbnet
Copy code
!|SCRIPT|
Option Explicit

' Set the new database type for tables
Dim newDBType
newDBType = "SQLServer"

' Get the current project
Dim currentProject
Set currentProject = Repository.GetProjectInterface

' Get the current model
Dim currentModel
Set currentModel = currentProject.Models.GetCurrentModel

' Get the selected package and its subpackages
Dim selectedPackage
Set selectedPackage = currentModel.GetTreeSelectedPackage
Dim packages
Set packages = selectedPackage.Packages.GetAllEx

' Loop through each package and change the database type for tables
Dim package
For Each package In packages
    Dim elements
    Set elements = package.Elements
    Dim element
    For Each element In elements
        If element.Type = "Table" Then
            element.MiscData("DBMS") = newDBType
            element.Update
        End If
    Next
Next

' Display a message when the script has finished
Session.Prompt "Finished updating database types for tables.", promptOK

!|ENDSCRIPT|
In this script, you first set the new database type for the tables by assigning it to the newDBType variable. Then, you get the current project and model using the GetProjectInterface and GetCurrentModel methods, respectively.

Next, you get the selected package and its subpackages using the GetTreeSelectedPackage method, and the GetAllEx method to get all the subpackages. You then loop through each package and get its elements. If an element is a table, you update its database type by setting the DBMS property of its MiscData dictionary to the new database type, and then calling the Update method to save the changes.

Finally, you display a message to indicate that the script has finished running.

To execute this script, you can follow the same steps as outlined in my previous answer, with the difference being that you need to select the package (and its subpackages) that you want to update before running the script. The script will only update the tables within the selected package and its subpackages, and will not affect any other elements in the model.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13402
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Using ChatGPT to create EA Scripts
« Reply #7 on: March 23, 2023, 04:30:59 pm »
Yeah, I'm afraid it only "looks" correct  :-\

- There is no such thing as Project.Models
- There is no Package.GetCurrentModel
- There is no Package.GetAllEx
- There is no element type "Table"
- There is no MiscData("DBMS")
-...

Geert

Richard Freggi

  • EA User
  • **
  • Posts: 493
  • Karma: +18/-7
    • View Profile
Re: Using ChatGPT to create EA Scripts
« Reply #8 on: March 23, 2023, 06:49:35 pm »
HAHA OK!  Reality check for me.  Thanks Geert!

Mauricio Moya (Arquesoft)

  • EA User
  • **
  • Posts: 341
  • Karma: +8/-4
  • EA Consulting and development in Spanish
    • View Profile
    • Arquehub Azure Module
Re: Using ChatGPT to create EA Scripts
« Reply #9 on: March 31, 2023, 02:58:50 am »
As I see it, there are two scenarios where ChatGPT can be used. One is for generating scripts, which effectively have many flaws, but it is possible to ask ChatGPT to correct them as they arise.

The other scenario is for generating SQL that can be used in SQL searches or in TimeSeriesCharts, ModelViews, or Simple Charts.

In any case, although the generation is not perfect, it allows a novice user to get an idea of how to proceed and try to make manual changes or ask ChatGPT to correct it until they get the perfect result. I think the goal in scripting should not be the generation of a complete script, but rather the creation of methods that can then be assembled to follow a general logic. In other words, we should ask ChatGPT prompts like "create a method that receives an ElementID and does X or Y".


Ian Mitchell

  • EA User
  • **
  • Posts: 506
  • Karma: +22/-4
  • The eaDocX and Model Expert guy
    • View Profile
Re: Using ChatGPT to create EA Scripts
« Reply #10 on: April 05, 2023, 03:13:53 am »
I agree with all of the above.
And remember, as several AI experts have said recently, this is as BAD as it will ever be.
It will only improve.
Ian Mitchell, Designer, eaDocX


www.eaDocX.com
www.theartfulmodeller.com