我想以编程方式向企业架构图中的连接器添加注释。到目前为止,我只使用以下代码向元素添加了注释:
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();
这张照片也许能让我更清楚地知道我到底想要什么:
png.htm
我的问题是:如何将便条附加到连接器上?我想我必须更改这一行"newConn.SupplierID = conn.SupplierID;",但是"newConn.SupplierID = conn.ConnectorID“会导致异常。如果有人能帮我,我会很高兴的!
诚挚的问候
发布于 2014-02-18 08:32:16
EA处理到连接器的注释链接与元素的便笺链接非常不同。
连接器总是在两个元素之间运行。在您的示例中,有四个元素(两个类型为Activity
,名为O1和O2,两个类型为Note
;它们通常是匿名的)和三个连接器(O1 - O2,“I‘s what”- O2,以及一个来自O1的连接器,它们从图像的边缘运行)。
从“这是我想要的”到O1 - O2连接器看上去像是连接器,实际上,它根本不是一个连接器--它看起来就像一个连接器。在GUI中,连接器的链接没有响应性,您不能为它打开一个属性对话框。这就是为什么。
将便笺链接到连接器的事实存储在note元素本身、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 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();
}
您可能需要在数据库更新之后设置元素子类型,我不确定。
Element.Subtype
值在API中是没有文档化的,Element.MiscData
的内容也是如此,所以这个解决方案并不是未来的证明(但是EA永远不会改变它处理这些事情的方式)。
https://stackoverflow.com/questions/21826184
复制相似问题