The namespace and context differ somewhat outside of ER/Studio DA's Macro Editor. External programs use the COM interface. For example, in an external Visual BASIC project, the base object is ERStudio.Application, whereas the base object in the ER/Studio DA Macro environment is DiagramManager. The object models and instantiation sequence are otherwise identical.
There is a working example VB application installed with ER/Studio DA. It is located in your installation directory under ”..\Program Files\ERStudio Data Architect X.X\Readme\TableList.zip.” Other examples of this type exist in MSVB6, .Net VB, and C#, and are in the same directory.
To run it, open the archive file TableList.zip and follow steps 1-3 below.
If you’re familiar with COM programming, skip to step 3 and the code segments below to configure your VB project for ER/Studio DA.
1. Copy Pubs.dm1 to C:\.
Pubs.dm1 is bundled with the application and is in:
• Windows XP: C:\Documents and Settings\All Users\Application Data\Embarcadero\ERStudioDA_X.X\Sample Models
• Windows Vista: C:\ProgramData\Embarcadero\ERStudioDA_X.X\Sample Models
• AppWave ION: My Documents\ERStudio Data Architect XE\Sample Models
2. Using MS Visual Basic 6.0 (or later), open the VB project file TableList.vbp.
3. Make sure your project refers to the ER/Studio DA type library:
a) Choose Project > References...
b) Select ER/Studio DA Type Library from the list.
4. Add the following declarations at the appropriate scope. They’re at module scope in the example TableList.bas: '
Option Explicit 'Require object declarations
Public app As ERStudio.Application 'Specify as ER/Studio types rather than "Object"
Public diagm As ERStudio.Diagram
Public mdl As ERStudio.Model
Public ent As ERStudio.
5. And instantiate in this way:
Set app = CreateObject("ERStudio.Application") 'Start ER/Studio DA if not running
Set diagm = app.OpenFile("C:\Pubs.dm1") 'Instantiate a diagram
Set mdl = diagm.ActiveModel 'Instantiate a model
Macros which run inside ER/Studio DA's SAX BASIC shell will use the pre-initialized 'DiagramManager' object. There are numerous examples of this in ER/Studio DA's Macro tab and in the Code Samples section of help.
Good Programing Practice: Use the DiagramManager.GetLastErrorCode() or DiagramManager.GetLastErrorString() to check for errors after method calls.
To summarize: Outside ER/Studio DA you begin with an instance of ERStudio.Application. Inside you begin with DiagramManager, and an instance is already running.