Book a Demo

Author Topic: Create a stereotype by script in the list  (Read 5389 times)

utilisateurEA

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Create a stereotype by script in the list
« on: April 12, 2010, 08:16:57 pm »
hello,

Is it possible to create, by script, a stereotype in the stereotype list ?

Thank you

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create a stereotype by script in the list
« Reply #1 on: April 12, 2010, 08:45:16 pm »
Can't you use Repository.Stereotypes?

Geert

Krzysztof Swiatkowski

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
  • Understanding is a three-edged sword
    • View Profile
Re: Create a stereotype by script in the list
« Reply #2 on: April 12, 2010, 10:03:19 pm »
for EAP files you can also use command line vbscript and SQL.
test.vbs:
Code: [Select]
Set conn=CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=test.eap"
set TypeLib = CreateObject("Scriptlet.TypeLib")
GUID = Left(TypeLib.GUID, Len(TypeLib.GUID)-2 )
sql="INSERT INTO t_stereotypes ([Stereotype], [AppliesTo], [Description], [ea_guid] ) VALUES ('new_stereo', 'class', 'description', '" + GUID + "' );"
conn.execute sql

Theoretically below automation code should work too but ea throws some error....
Code: [Select]
Set Repo=CreateObject("EA.Repository")
Repo.OpenFile("test.eap")
Set sts = Repo.Stereotypes
set newSt = sts.AddNew("testStereo1", "class")
newSt.Update()

Kris
If I put you finger in the eye
then you have finger in the eye
and I have finger in the eye
but it's not the same

utilisateurEA

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Create a stereotype by script in the list
« Reply #3 on: April 13, 2010, 12:39:21 am »
In my case "AddNew" does not cause any mistake but does not create a new stereotype (it does not do anything in fact...)

I tried your solution Ged but in a different way. It didn't work when I copied/paste in a script but I think it is because of the path, etc (but I changed "Data Source=test.eap" with the name of my project...)
so I tried SQLQuery as :
R.SQLQuery("INSERT INTO t_stereotypes ([Stereotype], [AppliesTo], [Description], [ea_guid] ) VALUES ('new_stereo', 'class', 'description', '87F83256-D225-4829-4113-AA311C92A166');");

(the number of GUID does not correspond to anything I have changed  an existing GUID to have a new one)

and I have the following mistake : "the select statement includes a reserved word that is misspelled or the punctuation is incorrect"

Do you have an idea of the cause of this mistake (I don't think it is my GUID because I have also tried with an attributed GUID and I have the same mistake)
« Last Edit: April 13, 2010, 05:02:13 pm by utilisateurEA »

Krzysztof Swiatkowski

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
  • Understanding is a three-edged sword
    • View Profile
Re: Create a stereotype by script in the list
« Reply #4 on: April 13, 2010, 07:24:19 am »
ok. I checked again and when I create file "test.vbs" in the same directory as "test.eap" it works for me.
As for SQLQuery if it worked it would prove documentation to be wrong because EA docs state that:
"Enables execution of a SQL select statement ..."

Funny thing is that if you put following code into ea scripts (View->Scripting) it works though it is almost identical to previous one :)

Code: [Select]
Sub AddSt
      dim stereotypes as EA.Collection
      set stereotypes = Repository.Stereotypes
      
      dim testStereo as EA.Stereotype
      set testStereo = stereotypes.AddNew( "Test12410", "Class" )

      testStereo.Update()
      stereotypes.Refresh()
      
      Session.Output( "Added Stereotype: " & testStereo.Name )
      
      set testStereo = nothing
End sub

AddSt

Kris
If I put you finger in the eye
then you have finger in the eye
and I have finger in the eye
but it's not the same

utilisateurEA

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Create a stereotype by script in the list
« Reply #5 on: April 13, 2010, 05:03:13 pm »
Thanks ged !

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create a stereotype by script in the list
« Reply #6 on: April 13, 2010, 05:05:03 pm »
Could it be that you got an error earlier because of the difference betwee "class" and "Class"?

Geert