Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: SomersetGraham on March 11, 2010, 07:59:23 pm

Title: How to link a note to an element feature
Post by: SomersetGraham on March 11, 2010, 07:59:23 pm
Hi all
This thread is a feedback on thread
http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1268231528

I have managed to find a way to achieve this but would appreciate any comments in case I have done something wrong!

Linking to element notes
Code: [Select]
string query = "UPDATE t_object SET PDATA1='Element Note' WHERE Object_ID=" + noteElement.ElementID;
Repository.Execute(query);
query = "UPDATE t_object SET PDATA2=" + TargetElement.ElementID + " WHERE Object_ID=" + noteElement.ElementID;
Repository.Execute(query);
query = "UPDATE t_object SET PDATA4='Yes' WHERE Object_ID=" + noteElement.ElementID;
Repository.Execute(query);
This pattern can be followed for other link options but for some of these you need to use PDATA3 as well

Thanks

Graham
Title: Re: How to link a note to an element feature
Post by: Geert Bellekens on March 11, 2010, 08:06:07 pm
Graham,

Good that you got it working, and thanks for sharing the solution.
But ultimately this solution is a very ugly workaround. This functionality should be provided as a standard API call.
You can request a feature using the link on the bottom of the page.
This will get the feature request on the internal Sparx list, but unfortunately it will not guarantee implementation.

Geert
Title: Re: How to link a note to an element feature
Post by: SomersetGraham on March 11, 2010, 08:10:47 pm
Hi Geert
Feature request made!
Title: Re: How to link a note to an element feature
Post by: Hurra on May 16, 2017, 06:21:14 pm
No news regarding the feature request? I would also like a "clean" solution to link a note to an element feature without the SQL query workaround!

But if I have to do it this way, is it easiest to do a diagram script, select target/source element and execute? Perhaps it's enough to execute the script on the link/relation?

Cheers.
Title: Re: How to link a note to an element feature
Post by: Hurra on May 16, 2017, 09:54:39 pm
I used c as EA.Connector to investigate which link that was of type NoteLink and tried:
Code: [Select]
                                                  Session.Output(c.SupplierID + " -------------- " + c.ClientID);
                                                  query = "UPDATE t_object SET PDATA1='Element Note' WHERE Object_ID="+ c.SupplierID;
                                                  Repository.Execute(query);
                                                  query = "UPDATE t_object SET PDATA2=" + c.ClientID + " WHERE Object_ID=" + c.SupplierID;
                                                  Repository.Execute(query);
                                                  query = "UPDATE t_object SET PDATA4='Yes' WHERE Object_ID=" + c.SupplierID;
                                                  Repository.Execute(query);

and got the error

Error: Microsoft OLE DB Provider for SQL Server [-2147217913]

Operand type clash: int is incompatible with ntext, Line:45

Any tips?

Title: Re: How to link a note to an element feature
Post by: Helmut Ortmann on May 17, 2017, 12:03:44 am
Hello,

the Open Source Addin hoTools (https://github.com/Helmut-Ortmann/EnterpriseArchitect_hoTools) allows you to do this by one click:
- Select Element, Operation, or Attribute on the Diagram
- Click on Feature
hoTools adds a Note which is connected to the selected item.

Kind regards,

Helmut
Title: Re: How to link a note to an element feature
Post by: Hurra on May 17, 2017, 05:58:20 pm
Actually the there were nothing wrong with the queries. There was just a pair of ' ' missing in the second query:

Code: [Select]
query = "UPDATE t_object SET PDATA1='Element Note' WHERE Object_ID=" + c.ClientID;       
Repository.Execute(query);
query = "UPDATE t_object SET PDATA2='" + c.SupplierID + "' WHERE Object_ID=" + c.ClientID;
Repository.Execute(query);
query = "UPDATE t_object SET PDATA4='Yes' WHERE Object_ID=" + c.SupplierID;
Repository.Execute(query);

However, I would also like to refresh the diagram to show the changes in the database, or refresh the Note.

I have these "objects" available:

e as EA.Element (selected from project browser)
c as EA.Connector (from e.Connectors.GetAt())
d as EA.Diagram (from e.Diagrams.GetAt())

My idea was as following:

Code: [Select]
if (d.DiagramID == c.DiagramID)
{
d.DiagramObjects.Refresh;
}

but the script never enters this if statement. Why?

Let me know if you need more code!
Title: Re: How to link a note to an element feature
Post by: Hurra on May 17, 2017, 06:21:35 pm
I just looked up e.Diagrams which do not yield the result I expected...
Code: [Select]
Diagrams
Collection
Read only
Returns a collection of sub-diagrams (child diagrams) attached to this element as seen in the tree view.

I thought it returned a collection of diagrams where the element has occurences.

How can I refresh/update my diagram?
Title: Re: How to link a note to an element feature
Post by: Hurra on May 17, 2017, 06:59:19 pm
Sorry for spamming the thread. Ez solution for my last question:
Code: [Select]
var d as EA.Diagram;
d = Repository.GetCurrentDiagram();
Repository.ReloadDiagram(d.DiagramID);