Enterprise Architect 9:向连接器添加注释 [英] Enterprise Architect 9: Add Note to Connector

查看:110
本文介绍了Enterprise Architect 9:向连接器添加注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式向Enterprise Architect图中的连接器添加注释.到目前为止,我仅设法通过以下代码向元素添加注释:

  foreach(Package.Elements中的EA.Element元素){foreach(element.Connectors中的EA.Connector conn){EA.Element newNote = Package.Elements.AddNew("MyNote","Note");newNote.Notes =某些字符串";newNote.Update();//这里不计算位置EA.DiagramObject k =图表.DiagramObjects.AddNew(position,");k.ElementID = newNote.ElementID;k.序列= 9;k.Update();EA.Connector newConn = newNote.Connectors.AddNew("NewLink","NoteLink");newConn.SupplierID = conn.SupplierID;newConn.Update();EA.DiagramLink newLink = diagram.DiagramLinks.AddNew("newLink","NoteLink");newLink.ConnectorID = newConn.ConnectorID;newLink.Update(); 

图像可能会更清楚我的实际需求:

http://www.directupload.net/file/d/3536/6bkijpg2_png.htm

我的问题是:如何将便笺附加到连接器上?我假设我必须更改此行"newConn.SupplierID = conn.SupplierID;",但是"newConn.SupplierID = conn.ConnectorID"会导致异常.如果有人可以帮助我,我将非常高兴!

最诚挚的问候

解决方案

EA处理连接器的注释链接与元素的注释链接大不相同.

连接器始终在两个元素之间运行.在您的示例中,有四个元素(两个活动类型为O1和O2的 Activity 类型,两个通常为无名的 Note 类型)和三个连接器(O1-O2,这就是我所拥有的"-O2,O1中的一个跑出图像边缘.

从这就是我想要的"到O1-O2连接器的连接器实际上根本不是连接器-看起来像一个连接器.在GUI中,到连接器的链接没有响应,因此您无法为其显示属性对话框.这就是为什么.

便笺已链接到连接器的事实存储在便笺元素本身的 MiscData 集合中.您需要做的是将字符串 idref =< connector_id> ;; 添加到 MiscData(3).您可能还需要将 Note Subtype 字段设置为1.

但是, MiscData 是只读的,因此您必须进入数据库并直接更新 t_object (存储元素的位置).API中的 MiscData 对应于表中的 PDATA1 等.请注意,索引相差一个,因此 MiscData(0)对应于 PDATA1 ,等等.

您还需要使用未记录的 Repository.Execute(),因为 Repository.SQLQuery()仅允许 select 语句.

因此,以下方法应该起作用:

  foreach(EA.Connector conn在element.Connectors中){EA.Element newNote = Package.Elements.AddNew("MyNote","Note");newNote.Subtype = 1;newNote.Notes =某些字符串";newNote.Update();repository.Execute("update t_object set PDATA4 ='idref =" + conn.ConnectorID +;""+其中Object_ID ="+ newNote.ElementID);//这里不计算位置EA.DiagramObject k =图表.DiagramObjects.AddNew(position,");k.ElementID = newNote.ElementID;k.序列= 9;k.Update();} 

我不确定您可能需要在数据库更新后设置元素子类型.

API中未记录

Element.Subtype 值,以及 Element.MiscData 的内容,因此该解决方案不是面向未来的(但不太可能)EA将会改变它处理这些事情的方式.

I want to add notes to connectors in an Enterprise Architect diagram programmatically. So far I only managed to add notes to elements with the following code:

 foreach (EA.Element element in Package.Elements)
            {
                foreach (EA.Connector conn in element.Connectors)
                {
                            EA.Element newNote = Package.Elements.AddNew("MyNote", "Note");
                            newNote.Notes = "Some string";
                            newNote.Update();

                            //position calculation is left out here
                            EA.DiagramObject k = diagram.DiagramObjects.AddNew(position, "");
                            k.ElementID = newNote.ElementID;
                            k.Sequence = 9;
                            k.Update();

                            EA.Connector newConn = newNote.Connectors.AddNew("NewLink", "NoteLink");
                            newConn.SupplierID = conn.SupplierID;
                            newConn.Update();

                            EA.DiagramLink newLink = diagram.DiagramLinks.AddNew("newLink", "NoteLink");
                            newLink.ConnectorID = newConn.ConnectorID;
                            newLink.Update();

The image maybe makes it more clear what I actually want:

http://www.directupload.net/file/d/3536/6bkijpg2_png.htm

My question is: How do I get the note attached to the connector? I assume I have to change this line "newConn.SupplierID = conn.SupplierID;", but "newConn.SupplierID = conn.ConnectorID" causes an exception. I would be very happy if someone could help me!

Best regards

解决方案

EA handles note links to connectors very differently from note links to elements.

Connectors always run between two elements. In your example, there are four elements (two of type Activity named O1 and O2, and two of type Note; these are usually nameless) and three connectors (O1 - O2, "This is what I have" - O2, and one from O1 running off the edge of the image).

The thing that looks like a connector from "This is what I want" to the O1 - O2 connector is not, in fact, a connector at all -- it just looks like one. In the GUI, the link to a connector is unresponsive and you can't bring up a properties dialog for it. This is why.

The fact that the note is linked to the connector is stored in the note element itself, in the MiscData collection. What you need to do is add the string idref=<connector_id>; to MiscData(3). You may also need to set the Note's Subtype field to 1.

However, MiscData is read-only so you'll have to go into the database and update t_object (where elements are stored) directly. MiscData in the API corresponds to PDATA1 etc in the table. Note that the indices differ by one, so MiscData(0) corresponds to PDATA1, etc.

You will also need to use the undocumented Repository.Execute() since Repository.SQLQuery() only allows select statements.

So the following should work:

foreach (EA.Connector conn in element.Connectors) {
    EA.Element newNote = Package.Elements.AddNew("MyNote", "Note");
    newNote.Subtype = 1;
    newNote.Notes = "Some string";
    newNote.Update();
    repository.Execute("update t_object set PDATA4='idref=" + conn.ConnectorID + ";' " +
      where Object_ID=" + newNote.ElementID);

    //position calculation is left out here
    EA.DiagramObject k = diagram.DiagramObjects.AddNew(position, "");
    k.ElementID = newNote.ElementID;
    k.Sequence = 9;
    k.Update();
}

You may need to set the element subtype after the database update, I'm not sure.

Element.Subtype values are undocumented in the API, as are the contents of Element.MiscData, so this solution isn't future-proof (but it's very unlikely EA will ever change the way it handles these things).

这篇关于Enterprise Architect 9:向连接器添加注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆