简体   繁体   中英

How to get the selected element in a diagram trough and Add-In in Enterprise Architect?

I'm currently developing an Add-In with a variety of functions, one of them to align ports in a diagram horizontally.

Therefore, I need to get the current selected element/ port in a diagram ( in this case Hand(Port4)) as an "anchor" element so that the other selected ports align themselves to the same x - coordinate.

Example diagram I'm working on我正在处理的示例图

In EA itself, it works wonderfully with

Select Object_ID, Name from t_object where Object_id = #CurrentElementID#

Going into my Add-In (that I'm developing in C# in Visual Studio 2022), I thought that I could do the same with a SQLQuery a la

String selectedPort = repository.SQLQuery("Select Object_ID, Name from t_object where Object_ID = #CurrentElementID# ");

Which gives me a syntax error at Object_ID = #CurrentElementID# and I don't know why tbh. I found thislink where #OBJECTID# was suggested but that didn't work either.

How do I get around this problem and get the port.top - value so that I can align the other ports to it?

You can not use the #-enclosed keywords except in custom SQL (from the search builder). So you have to use EADiagram.SelectedObjects which is a collection. repository.GetCurrentDiagram will give you the according diagram object. You need to check if the collection contains only a single element and use that. From here you can find the elementId/ObjectId and place it in your query.

Since you are using an add-in it's probably easier to use EA_OnContextItemChanged which points you to the port you right clicked to start the add-in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM