javascript - Python 脚本无法保存连接器 - Enterprise Architect

标签 javascript python enterprise-architect

我正在尝试使用 Python 向 EA 模型添加新的连接器。不幸的是,当我的脚本运行时,它没有添加连接器。通过 EA Javascript 控制台用 Javascript 编写的相同脚本能够添加连接器。

奇怪的是 Python 脚本不会失败。它的行为就像添加了连接器一样。如果我刷新正在连接的元素,连接器似乎就在那里。我什至可以从 Python 控制台获取 ConnectorID。

python :

from win32com.client import Dispatch
import os

ea = Dispatch("EA.App")
rep = ea.Repository
path = os.path.normpath("C:/temp/eaFile.eap")

e1 = rep.GetElementByID(121228)
e2 = rep.GetElementByID(120663)
newCon = e1.Connectors.AddNew("","Association")
newCon.ClientID = e1.ElementID
newCon.SupplierID = e2.ElementID
newCon.Update()

JavaScript:

e1 = Repository.GetElementByID(121228);
e2 = Repository.GetElementByID(120663);
newCon = e1.Connectors.AddNew("", "Association");
newCon.ClientID = e1.ElementID;
newCon.SupplierID = e2.ElementID;
newCon.Update();

我希望连接器在 Enterprise Architect 中作为元素上的链接可见 - 从 Python 运行时我找不到它,从 Javascript 运行时我能够找到它。

最佳答案

由于某些奇怪的原因,您需要不带大括号调用更新。

e1 = rep.getelementbyguid("{B2F19D81-1475-41f2-BABD-AA66E11FAE10}")
e2 = rep.getelementbyguid("{86DFDB7C-0838-47eb-8402-384701170C34}")
con = e1.connectors.addnew("", "Dependency")
con.supplierId = e2.elementId
con.update

为我工作。我从来没有调查过为什么,我只是习惯了 EA 方式...

注意连接器已经设置了 clientId,因此您不需要该分配。


这是我的包装类的摘录

import win32com.client
from singleton import Singleton
import errorlogger
import eacodes
import xml.etree.ElementTree as ET
import re
import os

@Singleton
class Repository:
    def __init__(self):
        try:
            app = win32com.client.GetActiveObject("EA.App")
            self.eaRep = app.Repository
            models = self.eaRep.models
            done = True
        except Exception as e:
            print (e)
            done = False
        if not done:
            logger = errorlogger.ErrorLogger.Instance()
            logger._fatal("Can not find a running EA instance")

        self.base = self.eaRep.connectionstring
        if os.path.exists(self.base):
            path, self.base = os.path.splitext(self.base.lower())
        else:
            self.base = "server"
        self.wildcard = "%" if self.base == ".eap" else "*"

    def query(self, sql):
        root = ET.fromstring(self.eaRep.SQLQuery (sql))
        data = root.getchildren()
        if len(data) == 0: return []
        ds = data[0][0]
        rows = []
        for row in ds:
            cols = []
            for col in row.getchildren(): cols.append(col.text)
            rows.append(cols)
        return rows

它是从整体上剪下来的,但是你可以把它作为一个开始。 Singleton 可以在 SO (IIRC) 的某个地方找到。用法:

rep = Repository.Instance()
e = rep.getElementByGuid("{B2F19D81-1475-41f2-BABD-AA66E11FAE10}")
print e.name
for row in rep.query("SELECT name FROM t_object"):
    print row[0]

关于javascript - Python 脚本无法保存连接器 - Enterprise Architect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58758722/

相关文章:

javascript - 如何在 HTML 文本区域中找到光标位置(X/Y,而不是行/列)?

javascript - 什么可能会导致单独加载时运行良好的组合 JavaScript 出现错误?

schema - 如何在 SPARX Enterprise Architect 中在包级别设置数据库模式?

python - 对多个输入集的理解

python - 一些 Celery 任务有效,其他任务未注册

enterprise-architect - Enterprise Architect (Sparx Systems) - 在参数列表中添加参数名称和类型

exception - 向 Sparx Enterprise Architect 中的操作添加异常

javascript - JS 中切换音频

javascript - 哇 js 不能使用滚动

python - 如何根据成员资格创建项目集群?