How to open Image manager through Enterprise Architect API

被刻印的时光 ゝ 提交于 2019-12-11 16:04:51

问题


I am working on Enterprise Architect through C# add-ins. I need to display the image manager through automation where user can add directly add images on an "add image" button click in form.

I use the API Repository.InvokeConstructPicker() but it only opens the select package/class/component window. Is there an EA API available to open the Image Manager.


回答1:


No, there is none. There is the undocumented Respository.CustomCommand which can open several properties windows. But the image manager is not part of that (or it has not been discovered what parameters to supply).

Please see Edit2 below about adding new values to the table.

Edit: Based on another question I had to dig into this a bit deeper.

I found out that, although EA imports a number of different image formats, it internally uses PNG to store the image. Obviously their BMP-importer does not like all BMP formats (not so deep in that, but I seem to remember there's some 8/16 bit stuff; typical Windoze weirdness). Anyhow, I used this Python code snippet to retrieve some test image data, previously imported into EA:

import sys
import win32com.client
import base64
import xml.etree.ElementTree

eaRep = None
try:
    eaApp = win32com.client.GetActiveObject(Class="EA.App")
    eaRep = eaApp.repository
except:
    print "failure to open EA"
    sys.exit(2)

def dump():
    sqlRes = eaRep.SQLQuery("SELECT * FROM t_image")
    root = xml.etree.ElementTree.fromstring(sqlRes)
    for dataset in root:
        for data in dataset:
            for row in data:
                name = row[1].text
                print name
                data = row[3].text
                png = base64.standard_b64decode(data)
                file = open("c:/" + name + ".png", "wb")
                file.write(png)
                file.close()

dump()

This correctly extracted the images from the database.

Edit2: I was assuming that EA stores the png as base64, but that's not true. EA only delivers base64 on return of SQLQuery. But they internally just store the raw png in Image. So, unfortunately, you can not use Repository.Execute since it can not transport binary data - or at least I have not figured out how to do that. As a work around you can look into Repository.ConnectionString and open a native connection to the database. Once you have plugged the new picture(s) in the table you can use them via thier ImageID.

Contents of t_image:

  • ImageID : You just need to create an unique ID
  • Name : an arbitrary string
  • Type : fixed string Bitmap
  • Image : blob of a png

Here's a Python snippet that connects natively to an EAP file:

import pyodbc
db_file = r'''C:\Documents and Settings\Administrator\Desktop\empty.eap'''

odbc_conn_str = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=' + db_file
conn = pyodbc.connect(odbc_conn_str)
cursor = conn.cursor()
cursor.execute("select * from t_image")
row = cursor.fetchone()
if row:
    print(row)

Rather than printing the row with the image data (which shows that its contents is a png-blob) you can use it to actually issue an INSERT or UPDATE to modify t_image.



来源:https://stackoverflow.com/questions/50903306/how-to-open-image-manager-through-enterprise-architect-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!