ERWIN 7.3 replaces batch Attribute of Logical with Definition of Physical Model.

Keywords: Python Attribute Oracle Windows

ERWIN can directly convert ORACLE's statement into a model by means of anti-orientation, but in the process of generating logical model, the field of the statement will be the field of the statement, that is, the English name. How to change the English name into the Chinese name is a particular headache. One by one, it is too slow and troublesome to update (especially for such a lazy person like me). I found it online. The API interface of ERWIN can be directly invoked through Python. With excitement, I immediately searched for the API document of ERWIN and returned to the topic:

I. Tool preparation

1) Find ERwin_API_Ref.pdf in your Erwin installation directory. The document details the API functions and attributes of ERWIN.

2) Download python_2.7.13150.msi (32 bits), download pywin32-218.win32-py2.7.exe (that is, COM interface package), the above tools can be found online search.

3) Download ERWIN version 7.3.10 to install and crack the registration.

You can see that the following model logic models are all in English (the first two are hand-modified)

2. Writing Python Code to Realize Batch Change

The environment is under Windows 7 system, the code is as follows

#!/usr/bin/python
# -*- coding: cp936 -*-
import win32com.client

# Create COM objects
scapi = win32com.client.Dispatch('AllFusionERwin.SCAPI')
# conn=win32com.client.Dispatch('ADODB.Connection')
# Establishing a connection with the model in the persistent device
# source file
filename = "C:\\111.erwin"
# Target file
newfilename = "C:\\122.erwin"
scPUnit = scapi.PersistenceUnits.Add(filename, "RDO=yes")
# Establishing a connection for accessing model data in memory
scSession = scapi.Sessions.Add()
scSession.Open(scPUnit, 0, 0)
# Transaction control
scTranId = scSession.BeginTransaction()
# Get all Entity model objects
scMObjects = scSession.ModelObjects.Collect(scSession.ModelObjects.Root, 'Entity', 1)
for scObj in scMObjects:
    # Get the value of the Definition attribute
    try:
        scDefineName = scObj.Properties('Definition').Value
    except Exception, ex:
        scDefineName = ''
    try:
        scName = scObj.Properties('Name').Value
    except Exception, ex:
        scName = ''
# Object name assignment
    # print "His scName is %s" % scName
    # print "His scDefineName is %s" % scDefineName
    scObj.Properties('Physical_Name').Value = scName
    scObj.Properties('Name').Value = scDefineName
# Get all Attribute objects for the Entity
scAttrObjects = scSession.ModelObjects.Collect(scObj, 'Attribute', 1)
for scAttrObj in scAttrObjects:
    # scAttrDefineName = scAttrObj.Properties('Definition').Value
    # scAttrName = scAttrObj.Properties('Name').Value
    try:
        scAttrDefineName = scAttrObj.Properties('Definition').Value
    except Exception, ex:
        scAttrDefineName = ''
    try:
        scAttrName = scAttrObj.Properties('Name').Value
    except Exception, ex:
        scAttrName = ''
# Object name assignment
    scAttrObj.Properties('Physical_Name').Value = scAttrName
    scAttrObj.Properties('Name').Value = scAttrDefineName
scSession.CommitTransaction(scTranId)
# Save it as a new file
scPUnit.Save(newfilename, 'OVF=yes')
After the above software is installed, it can be executed directly on your computer, and the result will be as follows (all batches have been changed, python is so powerful)



Posted by lemmin on Sat, 09 Feb 2019 11:09:19 -0800