Instantiating the Parent Object in an External Application

From ER/Studio Data Architect
Jump to: navigation, search

Go Up to Automating ER/Studio Data Architect

The namespace and context differ somewhat outside of ER/Studio Data Architect'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 Data Architect Macro environment is DiagramManager. The object models and instantiation sequence are otherwise identical.

There is a working example VB application installed with ER/Studio Data Architect. It is located in your installation directory under "C:\Program Files\IDERA\ERStudio Data Architect 16.0\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 are familiar with COM programming, skip to step 3 and the code segments below to configure your VB project for ER/Studio Data Architect.

  1. Copy Pubs.dm1 to C:\.
    Pubs.dm1 is bundled with the application and is in:
    C:\ProgramData\IDERA\ERStudioDA_17.0\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 Data Architect type library:
    a) Choose Project > References...
    b) Select ER/Studio Data Architect Type Library from the list.
  4. Add the following declarations at the appropriate scope. They are 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 Data Architect 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 Data Architect's SAX BASIC shell will use the pre-initialized 'DiagramManager' object. There are numerous examples of this in ER/Studio Data Architect'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 Data Architect you begin with an instance of ERStudio.Application. Inside you begin with DiagramManager, and an instance is already running.

See Also