3. Introduction

Let me start with a

Question: What’s the best part of EA?
Answer: You can script it!

Of course you find a lot of other pros4, but scripting is definitely the most prominent advantage you will find in EA. Now you might ask the

Question: Why should I use scripting?
Answer: Because you often have repetitive work you want to automate.

That’s a simple answer and probably too simplistic. The following list shows some major tasks you can tackle with scripting:

  • Regular repetitive task: Repetitive would also mean you have to repeat a couple of step five to ten times. If that’s it you would probably not start coding a script. But for tasks which you can foresee to use regularly and which involve say a minimum of 5 steps you must consider writing a script.
  • Importing Data: If the build-in CSV import of EA is not sufficient you have the choice between manual import and a script. If it’s only a couple of lines you should take the manual path. But if either the file is larger or you have to do the import on a regular basis you have no other choice than scripting.
  • Consistency checks: Whenever you need to implement complex modeling rules it is necessary to cross check the model from time to time. A manual approach will certainly fail as the model complexity soon reaches the limits you can handle manually. So it is a good advice to script your own model checker.
  • Code generation: EA has a build-in scripting for code generation. If you have only minor requirements for code generation you can live with that. But when it’s going to be more complex this scripting language soon becomes too restrictive. Doing the same task with your preferred language will make things much easier.
  • Conversion of data: Sometimes you need to change class names, add tagged values or move elements according to changed modeling rules. A manual conversion often is not feasible. That’s why you will need scripting.
  • Fancy things: Changing the behavior of the tool can support your modeling tasks a lot. Assume that you need to restrict the creation of elements depending on the model context. Or you need to set tagged values in several elements at once when you create, update or delete an element. In such cases you will find scripting a real benefit!

You see: there are quite a number of reasons why you should consider using scripting in EA. But that brings us to the next

Question: Which language shall/can I use?
Answer: The one you are familiar with!

Of course the real answer it not that simple, but quite. EA has a build-in scripting machine which lets you write JScript and Visual Basic. The nice thing here is that you can write scripts on-the-fly.

If you are not familiar with these languages and you prefer another one (e.g. Python, Perl, Cxx or whatever) you can do this as well. The only thing you need to find out is how to access the EA object where you can send API messages. You then can use the IDE of your choice to debug your application.

I can not go into details specific to any IDE or language6. For that reason I will not give language specific coding examples but abstract code sequences you need to adapt to the language of your choice. The advantage is that you need to think a lot more about what you are doing rather than taking ready-to-run samples. So in the end you learn more and faster!

3.1 Notation

As the different languages use different syntax I will use the most common dot-notation with C-like syntax elements with curly brackets. As a Visual Basic scripter you need to know that

1 	for (<init>; <cond>; <post>) { <statements> }

translates to VB-like

1 	<init>
2 	while (<cond>) then
3 	  <statements>
4 	  <post>
5 	wend

The dot-notation is similar for most other languages (Perl and C++ use -> instead of the dot).

Object.attribute

denotes the public attribute of Object.

Object.method(<parms>)

likewise represents the method call method with parameters <parms> where the latter is a comma separated list of object7/name-tuples.

More specifically I will use the following notation8:

Primitive = ‘bool’ | ‘short’ | ‘long’ | ‘string’;
CamelCase = “type-writer string starting with upper case and no spaces”;
EAobject = ‘Ea’ CamelCase; (* e.g. EaElement or EaPackage *)
Object = ‘Object’ | ‘ActiveX’ | ‘DateTime’ | EAobject;
TypeDefinition = Primitive | Object; (* declare attribute type/method result *)
VoidTypeDefinition = ‘void’ (* methods declared as void don’t return a value *)
| TypeDefinition;
Attribute = TypeDefinition ‘ ‘ CamelCase; (* e.g. long ObjectID *)
Method = VoidTypeDefinition ‘ ‘ CamelCase ( ParameterList );
ParameterList = [Attribute {‘,’ Attribute}]; (* optional comma-separated list *)

For better distinguishability all EA provided objects are prefixed with Ea. In your preferred language you will probably use these names without the prefix or in a dot-format (e.g. EA.Element instead of EaElement).

Further this document makes frequent use of hyper-links taking you to other locations in this document where the according term is defined in more detail.