Book a Demo

Author Topic: Scripting Documentation?  (Read 11367 times)

ssands

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Scripting Documentation?
« on: July 06, 2016, 09:33:38 am »
Hi all, I can naviagate in the online help to this page:

http://sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/using_scripts.html

But all the links are dead! (and those are the pages I think I could really use right now).

Are the pages somewhere else?

Thanks.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Scripting Documentation?
« Reply #1 on: July 06, 2016, 11:55:03 am »
Just a guess, but those just look like placeholder topics that were never filled in.  Seems like they might have since been removed in the updated EA 13 help.  I'll check with our resident help guru.

If you are looking for general API reference documentation, see:
http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/reference.html

Otherwise, is there something specific that you are having trouble with?  Are you trying to use scripting for Diagrams?  Elements?  Model Search?  Simulation?

If you are having trouble generally creating and running scripts, can you please confirm whether you have EA Corporate editon or higher?

ssands

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: Scripting Documentation?
« Reply #2 on: July 07, 2016, 03:03:35 am »
Thanks for the reply.
I'm trying to remove the stereotype of all the elements in a package.

I'm reusing a script and can iterate through all the elements. I am setting element.stereotype to ""  (I also tried setting it to nothing) (I'm using VB script).

Neither seem to work. Also, there seems to be a "field" titled "Fully Qualified Stereotype" (I see it in a csv export), but I don't see how to access that at all.

Any ideas are appreciated.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Scripting Documentation?
« Reply #3 on: July 07, 2016, 05:58:17 am »
If you post (parts of) your script it would be easier for us to help.

Element.FQStereotype gives the fully qualified stereotype. See http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/element2.html

q.
« Last Edit: July 07, 2016, 06:00:56 am by qwerty »

ssands

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: Scripting Documentation?
« Reply #4 on: July 07, 2016, 06:56:19 am »
Thanks! I do see FQStereotype, however that is read-only, so not sure how to proceed on changing a stereotype.

Here's my code (largely taken from a provided example. The heart of it is that it "appears" that the stereotype is changed (from my output statements) but it doesn't actually change when I look in the project browser. Not sure if I am not setting the stereotype correctly, if I need to change the FQStereotype (and how I would do that), or if there are some other steps I am missing.
Thanks is advance for the help.
Here's the relevant snippet of code (print statements are the bulk of it  :) )

option explicit
!INC Local Scripts.EAConstants-VBScript
' NOTE: Requires a package to be selected in the Project Browser
'
sub ChangeElementsStereotype()

   ' Show the script output window
   Repository.EnsureOutputVisible "Script"
   
   ' Get the currently selected package in the tree to work on
   dim thePackage as EA.Package
   set thePackage = Repository.GetTreeSelectedPackage()
      
   if not thePackage is nothing and thePackage.ParentID <> 0 then
   
      dim i
   
      Session.Output( "VBScript Change Elements Stereotype" )
      Session.Output( "=======================================" )
      
      dim elements as EA.Collection
      set elements = thePackage.Elements

      ' Navigate the elements collection.
      dim currentElement as EA.Element
         for i = 0 to elements.Count - 1
         set currentElement = elements.GetAt( i )
         
         Session.Output( "Element: " & currentElement.Name )
         Session.Output( "Element.stereotype: " & currentElement.stereotype )
         'currentElement.stereotype = "asdf"  ' <==this didn't work either
         currentElement.stereotype = ""
         Session.Output( "Element Stereotype is now: " & currentElement.stereotype)
      next

      Session.Output( "Done!" )
      
   else
      ' No package selected in the tree
      MsgBox( "This script requires a package to be selected in the Project Browser." & vbCrLf & _
         "Please select a package in the Project Browser and try again." )
   end if


end sub

ChangeElementsStereotype()



qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Scripting Documentation?
« Reply #5 on: July 07, 2016, 07:18:49 am »
The reason is simple: you never call Element.Update() after the change. The FQ is r/o because it's constructed from the MDG and the stereotype name. You can not change that, but only Stereotype.

q.

ssands

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: Scripting Documentation?
« Reply #6 on: July 07, 2016, 07:47:08 am »
Awesome! That worked well.

Now...I can set the stereotype to some arbitrary string and that works...but I can't clear it.

I've tried variations on an empty string (""), Set currentElement.Stereotype = nothing, but it doesn't take.

Pardon my lack of scripting knowledge, as this is probably pretty straightforward.

Thanks again for our help.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Scripting Documentation?
« Reply #7 on: July 07, 2016, 09:40:28 am »
To clear the existing stereotype, you need to set StereotypeEx = "".

Assigning a value to Element.Stereotype is additive.  E.g. if the element already has a stereotype "a" and you set Stereotype = "b", then "b" becomes the primary stereotype, but "a" will still remain as a secondary stereotype.  If you set StereotypeEx = "b" however, the "a" stereotype would be completetly removed and replaced by "b".

Hope that helps.

ssands

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: Scripting Documentation?
« Reply #8 on: July 07, 2016, 09:42:06 am »
Thanks! Funny, I figured it out less than a minute before I received this.

Best,
Stu

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1353
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Scripting Documentation?
« Reply #9 on: July 08, 2016, 01:28:43 pm »
Some JScript which can do the same thing. Just change entry in conversions[] array near the top
http://sparxsystems.com/forums/smf/index.php/topic,31109.msg225418.html#msg225418
« Last Edit: July 08, 2016, 01:30:34 pm by Sunshine »
Happy to help
:)

ssands

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: Scripting Documentation?
« Reply #10 on: July 09, 2016, 04:14:37 am »
Thank you!