因此,以下方法应该起作用: 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.htmMy 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:向连接器添加注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 04:20