0% found this document useful (0 votes)
216 views

ERwinAPI TutorialSpreadsheet

This document provides examples for using the ERwin API to programmatically modify an ERwin data model. It includes high-level steps for connecting to a model, retrieving and modifying objects, and saving changes. Code snippets are presented in VBA to demonstrate basic API functions like getting object collections, finding specific objects, editing properties, and committing transactions. Guidance is provided on setting references to use different ERwin API versions.

Uploaded by

Ryan Riggs
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
216 views

ERwinAPI TutorialSpreadsheet

This document provides examples for using the ERwin API to programmatically modify an ERwin data model. It includes high-level steps for connecting to a model, retrieving and modifying objects, and saving changes. Code snippets are presented in VBA to demonstrate basic API functions like getting object collections, finding specific objects, editing properties, and committing transactions. Guidance is provided on setting references to use different ERwin API versions.

Uploaded by

Ryan Riggs
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 42

CA ERwin Data Modeler API Tutorial S

This spreadsheet uses MS Excel and VBA (Visual Basic for Applications) to provide example
provide a framework for creating custom ERwin API applications. Over ninety percent of ER

The data in this spreadsheet is setup to work with Entities and Attributes found in the eMovies sample model. You may m
they have when the API is run. The "Ingnore Case" version of the example will create attributes that are not found. So if
the attributes, however, this example does not recreate the Primary Keys.

High-level Overview of a Typical ERwin API How to Setup E


1.  Get the “Persistence Unit” (model) 1-
2. Create and open an API “session” with the Persistence Unit a
3. Get a collection of the types of objects you’re interested in b
4. Find a specific object from the collection
a. Call function to retrieve object or iterate collection 2-
b. Examine properties to select target object a
5. If desired, use the selected object to create a secondary object collection
a. Find a specific object from the secondary collection
6. Modify the selected object
a. Open a transaction (not required for read-only actions)
 i. Edit, create or remove a property
 ii. Create or delete an object b
b. Close the transaction
NOTE: The “granularity” of transactions can be used to control how
much data is committed or rolled back at each step.
7. Save the Persistence Unit
a. This step irrevocably commits changes to the model.
8. Close the session c
9. Cleanup d
e

Tip:

Use these examples in conjunction with the original eMovies model and with:
eMovies_API_Tutorial.erwin

NOTES:

The intent of these examples is to show the principles involved in creating an ERwin API
application. These examples happen to be written in VBA but the concepts are generic
and will apply no matter what language is used to create the API. There are some
syntactic differences with each language, but describing those differences is beyond
the scope of this tutorial.

The ERwin API exposes a standard COM interface so an ERwin API application may be
written using any language which supports COM. Implementation of a COM interface
varies from language to language so it is up to the user to determine the configuration
of that interface using the language of their choice.
Tutorial Spreadsheet
ons) to provide examples of using the ERwin API (also known as SCAPI). These examples demonstrate the ba
ver ninety percent of ERwin API applications may be written using only the functions included in these examp

es sample model. You may modify the values in the spreadsheet to see the effect
utes that are not found. So if all attributes are removed, that function will restore

How to Setup Excel to Edit Your ERwin Macros


If the Developer tab is not available, do the following to display it:
Click the Microsoft Office Button , and then click Excel Options.
In the Popular category, under Top options for working with Excel,
select the Show Developer tab in the Ribbon check box, and then click
OK.
To set the security level temporarily to enable all macros, do the following:
On the Developer tab, in the Code group, click Macro Security.

Under Macro Settings, click Enable all macros (not recommended,


potentially dangerous code can run), and then click OK.

Note: To help prevent potentially dangerous code from running, we


recommend that you return to any of the settings that disable all macros
after you finish working with macros.

On the Developer tab, in the Code group, click Macros.


In the Macro name box, click the macro that you want to edit.
Click Edit.

For Help with the Visual Basic Editor, on the Help menu, click
Microsoft Visual Basic Help, or press F1.

Before you edit a macro, you should be familiar with the Visual Basic Editor. The
Visual Basic Editor can be used to write and edit a macro that is attached to a
Microsoft Office Excel workbook.
as SCAPI). These examples demonstrate the basics of using the ERwin API and
sing only the functions included in these examples .

Setting the API for ERwin r7 or ERwin r8


The API includes references to COM libraries that are specific to the version of ERwin
that is being used. The following steps will allow you to change this API sample to work
with your version of CA ERwin Data Modeler.

1.  Switch to the Developer mode to view the VB code


a. Click the Developer Tab
b. Select "Visual Basic"

2. From the "Tools" menu, choose "References..."


3. You will see a checkmarked reference with the name:
"CA ERwin Data Modeler Script Client API Type Library"
4. Highlight that reference and note the path to EAL.dll
a. The path must match the ERwin version being used
5. To use a different version of the API, uncheck that reference
6. Scroll down and find a second reference named:
"CA ERwin Data Modeler Script Client API Type Library"
7. Highlight that reference and note the path to EAL.dll
a. Make sure the path now matches he ERwin version being
used
b. Check the box to select the matching version of EAL.dll
8. Click OK and save the spreadsheet

NOTE: You should have only one reference to EAL.dll so only one ERwin Script
Client API component should be selected.
CA ERwin Data Modeler API - RESET P
This utility will Reset the Specified Object
Properties
Enter values below then press the button →

Object Name: Attribute

Property Name: Null_Option_Constraint_Name

Property Value:
Left(scObject.Properties(sPropertyName).Value, 4) = "SYS_"
PI - RESET PROPERTY
ified Object Press
Press This
This Button
Button
to
to

e button →
RESET
RESET Object
Object
Properties
Properties

← Enter the name of the object that has the property you want to reset
← Enter the name of the property to reset (target property)
← Enter the new property value
(leave blank to remove the property)
Click the Arrow to Update Your Model

CASE-SENSITIVE
Rename Only

Entity Attribute
Existing Name Existing Name
CUSTOMER customer number
customer address
email
customer city
customer first name
customer last name
customer state
customer zip code
CUSTOMER CREDIT customer number
credit card
credit card exp
status code
EMPLOYEE employee number
supervisor
employee first name
employee address
employee address 2
employee phone
soc sec number
hire date
salary
email
store number
MOVIE movie number
movie title
movie director
description
star 1 name
rating
star 2 name
genre
rental rate
movie url
movie clip
MOVIE COPY movie copy number
movie number
general condition
movie format
MOVIE RENTAL RECORD rental record date
movie copy number
movie number
employee phone
soc sec number
customer number
rental date
due date
rental status
payment transaction number
overdue charge
rental rate
MOVIE_STORE movie number
store number
PAYMENT payment transaction number
payment type
payment amount
payment date
payment status
employee number
customer number__1214
customer number
check bank number
check number
epay vendor number
epay account number
credit card number
credit card exp
credit card type
STORE store number
store manager
store address
store address 2
store phone
store city
store state
store zip code

The information below may be used to restore the original Attribu


Entity Attribute
Original Name Original Name
CUSTOMER customer number
customer address
email
customer city
customer first name
customer last name
customer state
customer zip code
CUSTOMER CREDIT customer number
credit card
credit card exp
status code
EMPLOYEE employee number
supervisor
employee first name
employee address
employee address 2
employee phone
soc sec number
hire date
salary
email
store number
MOVIE movie number
movie title
movie director
description
star 1 name
rating
star 2 name
genre
rental rate
movie url
movie clip
MOVIE COPY movie copy number
movie number
general condition
movie format
MOVIE RENTAL RECORD rental record date
movie copy number
movie number
employee phone
soc sec number
customer number
rental date
due date
rental status
payment transaction number
overdue charge
rental rate
MOVIE_STORE movie number
store number
PAYMENT payment transaction number
payment type
payment amount
payment date
payment status
employee number
customer number__1214
customer number
check bank number
check number
epay vendor number
epay account number
credit card number
credit card exp
credit card type
STORE store number
store manager
store address
store address 2
store phone
store city
store state
store zip code
he Arrow to Update Your Model
Model
from aa Model
from
ATTRIBUTES
ATTRIBUTES
ALL
DELETE ALL
DELETE
IGNORE CASE - Rename This Button
Press This
Press to
Button to
Create Attribute if Missing

Attribute Column
New Name New Name
CUSTOMER-customer number COL_customer_number
CUSTOMER-customer address COL_customer_address
CUSTOMER-email COL_email
CUSTOMER-customer city COL_customer_city
CUSTOMER-customer first name COL_customer_first_name
CUSTOMER-customer last name COL_customer_last_name
CUSTOMER-customer state COL_customer_state
CUSTOMER-customer zip code COL_customer_zip_code
CUSTOMER CREDIT-customer number COL_customer_number
CUSTOMER CREDIT-credit card COL_credit_card
CUSTOMER CREDIT-credit card exp COL_credit_card_exp
CUSTOMER CREDIT-status code COL_status_code
EMPLOYEE-employee number COL_employee_number
EMPLOYEE-supervisor COL_supervisor
EMPLOYEE-employee first name COL_employee_first_name
EMPLOYEE-employee address COL_employee_address
EMPLOYEE-employee address 2 COL_employee_address_2
EMPLOYEE-employee phone COL_employee_phone
EMPLOYEE-soc sec number COL_soc_sec_number
EMPLOYEE-hire date COL_hire_date
EMPLOYEE-salary COL_salary
EMPLOYEE-email COL_email
EMPLOYEE-store number COL_store_number
MOVIE-movie number COL_movie_number
MOVIE-movie title COL_movie_title
MOVIE-movie director COL_movie_director
MOVIE-description COL_description
MOVIE-star 1 name COL_star_1_name
MOVIE-rating COL_rating
MOVIE-star 2 name COL_star_2_name
MOVIE-genre COL_genre
MOVIE-rental rate COL_rental_rate
MOVIE-movie url COL_movie_url
MOVIE-movie clip COL_movie_clip
MOVIE COPY-movie copy number COL_movie_copy_number
MOVIE COPY-movie number COL_movie_number
MOVIE COPY-general condition COL_general_condition
MOVIE COPY-movie format COL_movie_format
MOVIE RENTAL RECORD-rental record date COL_rental_record_date
MOVIE RENTAL RECORD-movie copy number COL_movie_copy_number
MOVIE RENTAL RECORD-movie number COL_movie_number
MOVIE RENTAL RECORD-employee phone COL_employee_phone
MOVIE RENTAL RECORD-soc sec number COL_soc_sec_number
MOVIE RENTAL RECORD-customer number COL_customer_number
MOVIE RENTAL RECORD-rental date COL_rental_date
MOVIE RENTAL RECORD-due date COL_due_date
MOVIE RENTAL RECORD-rental status COL_rental_status
MOVIE RENTAL RECORD-payment transaction number COL_payment_transaction_number
MOVIE RENTAL RECORD-overdue charge COL_overdue_charge
MOVIE RENTAL RECORD-rental rate COL_rental_rate
MOVIE_STORE-movie number COL_movie_number
MOVIE_STORE-store number COL_store_number
PAYMENT-payment transaction number COL_payment_transaction_number
PAYMENT-payment type COL_payment_type
PAYMENT-payment amount COL_payment_amount
PAYMENT-payment date COL_payment_date
PAYMENT-payment status COL_payment_status
PAYMENT-employee number COL_employee_number
PAYMENT-customer number__1214 COL_customer_number__1214
PAYMENT-customer number COL_customer_number
PAYMENT-check bank number COL_check_bank_number
PAYMENT-check number COL_check_number
PAYMENT-epay vendor number COL_epay_vendor_number
PAYMENT-epay account number COL_epay_account_number
PAYMENT-credit card number COL_credit_card_number
PAYMENT-credit card exp COL_credit_card_exp
PAYMENT-credit card type COL_credit_card_type
STORE-store number COL_store_number
STORE-store manager COL_store_manager
STORE-store address COL_store_address
STORE-store address 2 COL_store_address_2
STORE-store phone COL_store_phone
STORE-store city COL_store_city
STORE-store state COL_store_state
STORE-store zip code COL_store_zip_code

d to restore the original Attributes to the eMovies model


Attribute
Original Name
customer number
customer address
email
customer city
customer first name
customer last name
customer state
customer zip code
customer number
credit card
credit card exp
status code
employee number
supervisor
employee first name
employee address
employee address 2
employee phone
soc sec number
hire date
salary
email
store number
movie number
movie title
movie director
description
star 1 name
rating
star 2 name
genre
rental rate
movie url
movie clip
movie copy number
movie number
general condition
movie format
rental record date
movie copy number
movie number
employee phone
soc sec number
customer number
rental date
due date
rental status
payment transaction number
overdue charge
rental rate
movie number
store number
payment transaction number
payment type
payment amount
payment date
payment status
employee number
customer number__1214
customer number
check bank number
check number
epay vendor number
epay account number
credit card number
credit card exp
credit card type
store number
store manager
store address
store address 2
store phone
store city
store state
store zip code
Provide Entity names and Attribute names below
Logical Names
Entity
CUSTOMER

CUSTOMER CREDIT

EMPLOYEE

MOVIE
MOVIE COPY

MOVIE RENTAL RECORD

MOVIE_STORE

PAYMENT

STORE
Click the Arrow to Open a Model and Update the Spreadsheet

CASE-SENSITIVE
Find Table & Column Names

ames and Attribute names below


Logical Names
Attribute
CUSTOMER-customer number
CUSTOMER-customer address
CUSTOMER-email
CUSTOMER-customer city
CUSTOMER-customer first name
CUSTOMER-customer last name
CUSTOMER-customer state
CUSTOMER-customer zip code
CUSTOMER CREDIT-customer number
CUSTOMER CREDIT-credit card
CUSTOMER CREDIT-credit card exp
CUSTOMER CREDIT-status code
EMPLOYEE-employee number
EMPLOYEE-supervisor
EMPLOYEE-employee first name
EMPLOYEE-employee address
EMPLOYEE-employee address 2
EMPLOYEE-employee phone
EMPLOYEE-soc sec number
EMPLOYEE-hire date
EMPLOYEE-salary
EMPLOYEE-email
EMPLOYEE-store number
MOVIE-movie number
MOVIE-movie title
MOVIE-movie director
MOVIE-description
MOVIE-star 1 name
MOVIE-rating
MOVIE-star 2 name
MOVIE-genre
MOVIE-rental rate
MOVIE-movie url
MOVIE-movie clip
MOVIE COPY-movie copy number
MOVIE COPY-movie number
MOVIE COPY-general condition
MOVIE COPY-movie format
MOVIE RENTAL RECORD-rental record date
MOVIE RENTAL RECORD-movie copy number
MOVIE RENTAL RECORD-movie number
MOVIE RENTAL RECORD-employee phone
MOVIE RENTAL RECORD-soc sec number
MOVIE RENTAL RECORD-customer number
MOVIE RENTAL RECORD-rental date
MOVIE RENTAL RECORD-due date
MOVIE RENTAL RECORD-rental status
MOVIE RENTAL RECORD-payment transaction number
MOVIE RENTAL RECORD-overdue charge
MOVIE RENTAL RECORD-rental rate
MOVIE_STORE-movie number
MOVIE_STORE-store number
PAYMENT-payment transaction number
PAYMENT-payment type
PAYMENT-payment amount
PAYMENT-payment date
PAYMENT-payment status
PAYMENT-employee number
PAYMENT-customer number__1214
PAYMENT-customer number
PAYMENT-check bank number
PAYMENT-check number
PAYMENT-epay vendor number
PAYMENT-epay account number
PAYMENT-credit card number
PAYMENT-credit card exp
PAYMENT-credit card type
STORE-store number
STORE-store manager
STORE-store address
STORE-store address 2
STORE-store phone
STORE-store city
STORE-store state
STORE-store zip code
en a Model and Update the Spreadsheet

umn Names

Physical names (Table & Column names) are read from the model and written bel
Physical Names (read from model)
Table
ames) are read from the model and written below
Names (read from model)
Column
This function will:
DELETE ALL OBJECTS SPECIFIED BELOW
from the selected ERwin Model

Enter the object name here → Script_Template

Press
Press This
This Button
Button
to
to
DELETE
DELETE ALL
ALL
SPECIFIED
SPECIFIED
OBJECTS
OBJECTS
from
from the
the selected
selected
Model
Model
CA ERwin Data Modeler API - Harde

Click the Arrow to Update Your Model

HARDEN DATATYPES
I - Harden Datatypes
Entity Attribute
eMovies Name eMovies Name
CUSTOMER customer number
customer address
email
customer city
customer first name
customer last name
customer state
customer zip code
CUSTOMER CREDIT customer number
credit card
credit card exp
status code
EMPLOYEE employee number
supervisor
employee first name
employee address
employee address 2
employee phone
soc sec number
hire date
salary
email
store number
MOVIE movie number
movie title
movie director
description
star 1 name
rating
star 2 name
genre
rental rate
movie url
movie clip
MOVIE COPY movie copy number
movie number
general condition
movie format
MOVIE RENTAL RECORD rental record date
movie copy number
movie number
employee phone
soc sec number
customer number
rental date
due date
rental status
payment transaction number
overdue charge
rental rate
MOVIE_STORE movie number
store number
PAYMENT payment transaction number
payment type
payment amount
payment date
payment status
employee number
customer number__1214
customer number
check bank number
check number
epay vendor number
epay account number
credit card number
credit card exp
credit card type
STORE store number
store manager
store address
store address 2
store phone
store city
store state
store zip code
Attribute Column
Modified Name Modified Name
CUSTOMER-customer number COL_customer_number
CUSTOMER-customer address COL_customer_address
CUSTOMER-email COL_email
CUSTOMER-customer city COL_customer_city
CUSTOMER-customer first name COL_customer_first_name
CUSTOMER-customer last name COL_customer_last_name
CUSTOMER-customer state COL_customer_state
CUSTOMER-customer zip code COL_customer_zip_code
CUSTOMER CREDIT-customer number COL_customer_number
CUSTOMER CREDIT-credit card COL_credit_card
CUSTOMER CREDIT-credit card exp COL_credit_card_exp
CUSTOMER CREDIT-status code COL_status_code
EMPLOYEE-employee number COL_employee_number
EMPLOYEE-supervisor COL_supervisor
EMPLOYEE-employee first name COL_employee_first_name
EMPLOYEE-employee address COL_employee_address
EMPLOYEE-employee address 2 COL_employee_address_2
EMPLOYEE-employee phone COL_employee_phone
EMPLOYEE-soc sec number COL_soc_sec_number
EMPLOYEE-hire date COL_hire_date
EMPLOYEE-salary COL_salary
EMPLOYEE-email COL_email
EMPLOYEE-store number COL_store_number
MOVIE-movie number COL_movie_number
MOVIE-movie title COL_movie_title
MOVIE-movie director COL_movie_director
MOVIE-description COL_description
MOVIE-star 1 name COL_star_1_name
MOVIE-rating COL_rating
MOVIE-star 2 name COL_star_2_name
MOVIE-genre COL_genre
MOVIE-rental rate COL_rental_rate
MOVIE-movie url COL_movie_url
MOVIE-movie clip COL_movie_clip
MOVIE COPY-movie copy number COL_movie_copy_number
MOVIE COPY-movie number COL_movie_number
MOVIE COPY-general condition COL_general_condition
MOVIE COPY-movie format COL_movie_format
MOVIE RENTAL RECORD-rental record date COL_rental_record_date
MOVIE RENTAL RECORD-movie copy number COL_movie_copy_number
MOVIE RENTAL RECORD-movie number COL_movie_number
MOVIE RENTAL RECORD-employee phone COL_employee_phone
MOVIE RENTAL RECORD-soc sec number COL_soc_sec_number
MOVIE RENTAL RECORD-customer number COL_customer_number
MOVIE RENTAL RECORD-rental date COL_rental_date
MOVIE RENTAL RECORD-due date COL_due_date
MOVIE RENTAL RECORD-rental status COL_rental_status
MOVIE RENTAL RECORD-payment transaction number COL_payment_transaction_number
MOVIE RENTAL RECORD-overdue charge COL_overdue_charge
MOVIE RENTAL RECORD-rental rate COL_rental_rate
MOVIE_STORE-movie number COL_movie_number
MOVIE_STORE-store number COL_store_number
PAYMENT-payment transaction number COL_payment_transaction_number
PAYMENT-payment type COL_payment_type
PAYMENT-payment amount COL_payment_amount
PAYMENT-payment date COL_payment_date
PAYMENT-payment status COL_payment_status
PAYMENT-employee number COL_employee_number
PAYMENT-customer number__1214 COL_customer_number__1214
PAYMENT-customer number COL_customer_number
PAYMENT-check bank number COL_check_bank_number
PAYMENT-check number COL_check_number
PAYMENT-epay vendor number COL_epay_vendor_number
PAYMENT-epay account number COL_epay_account_number
PAYMENT-credit card number COL_credit_card_number
PAYMENT-credit card exp COL_credit_card_exp
PAYMENT-credit card type COL_credit_card_type
STORE-store number COL_store_number
STORE-store manager COL_store_manager
STORE-store address COL_store_address
STORE-store address 2 COL_store_address_2
STORE-store phone COL_store_phone
STORE-store city COL_store_city
STORE-store state COL_store_state
STORE-store zip code COL_store_zip_code

You might also like