Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Hurra on October 04, 2017, 07:46:18 pm
-
Hello!
I am creating some documentation/reports via script fragments. I would like to show specific diagrams. My first idea was to iterate through the element usage list (ctrl+u) and send diagrams to the report based on the name of the diagram.
However I didn't find anything like ctrl+u in the API, and didn't find it googling/searching the forum either. Does anyone know a method to create a collection with the diagrams like ctrl+u?
Is there a better approach to select specific diagrams?
Thank you!
-
I know I can use the documentation section
Package: Element: Usage: Diagram
but I can't exclude diagrams from the section. Or can I?
-
You can put it in fragment and then set a filter on the fragment.
With regular script or SQL fragment you can't output diagram images.
Geert
-
Hi,
I'm not aware of an API call that does this. I'd say the simplest way is to use Repository.SQLQuery() and parse the resulting XML data.
You need to match t_object.Object_Id or t_object.Classifier to t_diagramobjects.Object_ID, and t_diagramobjects.Diagram_ID to t_diagram.Diagram_ID.
HTH,
/Uffe
-
Thank you for your help!
I did as Uffe said; SQL Query and matching the ID's.
I now get my data as following rows:
<Row><CLASSGUID>{xx}</CLASSGUID><CLASSTYPE>Type</CLASSTYPE><Name>Element name</Name><Diagram>Diagram name</Diagram><DiagramID>xx</DiagramID></Row>
My first problem is to parse this data from the XML-format.
I tried to use JScript-XML and the function XMLGetNodeText/XMLGetNodeTextArray with no success.
Also I do not know which of the following solutions are best.
I want to be able to chose which diagrams to include in the report. I believe it is easiest to choose diagram based on their names since we have an abbreviation in the end of the diagram names. However, when sending the diagram to the report I am more interested in the DiagramID.
Should I create a new object? myDiagram.name and .id? Should I have two arrays? One with string one with int? How would you do this?
I appreciate all your help!
EDIT:
I manage to fetch the first entry of DiagramID through
var DOMDoc = XMLParseXML(SQLresult);
var DiagramIDs = XMLGetNodeText( DOMDoc, "EADATA/Dataset_0/Data/Row/DiagramID" );
However, I (almost) always has several rows. I can't get XMLGetNodeTextArray to work. Or should I somehow loop XMLGetNodeText?
Dunno why I didn't get this to work before but
var DOMDoc = XMLParseXML(SQLresult);
var DiagramIDs = XMLGetNodeTextArray( DOMDoc, "//Row/DiagramID" );
works fine!
I also realized the problem Bellekens pointed out; With regular script or SQL fragment you can't output diagram images.
But if I set this up as Document Script I can choose what to send to the built in section editor?
-
Hi,
Please see some vbscript I use with Repository.SQLQuery below (so I'm not using JavaScript):
set dom = CreateObject ("MSXML2.DOMDocument")
xml = Repository.SQLQuery (sql)
dom.setProperty "SelectionLanguage", "XPath"
dom.loadXML (xml)
for each node In dom.SelectNodes ("//Row")
pid = node.selectSingleNode("./pid").Text
did = node.selectSingleNode("./did").Text
...
NEXT
-
I have managed to select diagrams with SQL query, collect the diagramIDs, select diagrams of interest with IF, send it to template with document script.
It works fine, I generate the report I want but I get this strange error code.
(https://i.imgur.com/1yOMPNa.png)
My SQL query is:
"SELECT t_object.ea_guid AS CLASSGUID, t_object.Object_Type AS CLASSTYPE, t_object.Name AS Name, t_diagram.Name AS Diagram, t_diagram.Diagram_ID AS DiagramID
FROM t_object, t_diagram, t_diagramobjects
WHERE t_object.Object_ID LIKE " + objectID + " AND t_diagramobjects.Object_ID = t_object.Object_ID AND t_diagramobjects.Diagram_ID = t_diagram.Diagram_ID
ORDER BY t_diagram.Name"
I get the correct result, but that annoying error message.
Anyone know why?
-
I would write it like this:
"SELECT o.ea_guid AS CLASSGUID, o.Object_Type AS CLASSTYPE, o.Name AS Name, d.Name AS Diagram, d.Diagram_ID AS DiagramID
FROM t_object o
INNER JOIN t_diagramobjects do ON do.Object_ID = o.Object_ID
INNER JOIN t_diagram d ON d.Diagram_ID = do.Diagram_ID
WHERE o.Object_ID =" + ObjectID +
ORDER BY Diagram"
I've never had the error you mentioned, maybe the above version doesn't have the issue.
Geert
-
I would write it like this:
"SELECT o.ea_guid AS CLASSGUID, o.Object_Type AS CLASSTYPE, o.Name AS Name, d.Name AS Diagram, d.Diagram_ID AS DiagramID
FROM t_object o
INNER JOIN t_diagramobjects do ON do.Object_ID = o.Object_ID
INNER JOIN t_diagram d ON d.Diagram_ID = do.Diagram_ID
WHERE o.Object_ID =" + ObjectID +
ORDER BY Diagram"
I've never had the error you mentioned, maybe the above version doesn't have the issue.
Geert
Thank you for your input! Your query works good, although I get a similar error:
(https://i.imgur.com/HO9mumd.png)
The generated report still looks good!
-
Look into %appdata%\Sparx Systems\DBerror.txt or turn on the profiler on your SQL server.
That should given you some more info on the error you are getting. It will probably be something other then this actual query.
Geert
-
Look into %appdata%\Sparx Systems\DBerror.txt or turn on the profiler on your SQL server.
That should given you some more info on the error you are getting. It will probably be something other then this actual query.
Geert
I isolated the problem to the function where I call the SQL-query and I think I know the problem.
I tried to print the result from the query and actually got two outputs:
Script Trace - <?xml version="1.0"?>
<EADATA version="1.0" exporter="Enterprise Architect">
</EADATA>
Script Trace - <?xml version="1.0"?>
<EADATA version="1.0" exporter="Enterprise Architect">
<Dataset_0><Data><Row><CLASSGUID>{xx}</CLASSGUID><CLASSTYPE>type</CLASSTYPE><Name>name</Name><Diagram>diagram name</Diagram><DiagramID>xx</DiagramID></Row></Data></Dataset_0></EADATA>
My guesss is that the first part yields the error since "//Row/DiagramID" can't be found.
Any thoughts about this?
I did not have this kind of output before though..? Don't know what might of happened.
Function:
!INC Local Scripts.EAConstants-JScript
!INC EAScriptLib.JScript-XML
function getDiagramOccurences( objectID /* : ElementID */ ) // Output: Array
{
var SQLresult = Repository.SQLQuery("SELECT o.ea_guid AS CLASSGUID, o.Object_Type AS CLASSTYPE, o.Name AS Name, d.Name AS Diagram, d.Diagram_ID AS DiagramID FROM t_object o INNER JOIN t_diagramobjects do ON do.Object_ID = o.Object_ID INNER JOIN t_diagram d ON d.Diagram_ID = do.Diagram_ID WHERE o.Object_ID = " + objectID + " ORDER BY Diagram");
var DOMDoc = XMLParseXML(SQLresult);
var DiagramIDs = XMLGetNodeTextArray( DOMDoc, "//Row/DiagramID" );
return DiagramIDs;
}
-
The error is a database error, not an XmlDom error, so it should be something on the database side.
EA does some pre-processing with the SQL's we send trough, so it might be related to that. I would really look into the dbError.txt and what you can see on the profiler.
Might not be related, but if you are only interested in the DiagramID, why are you returning all those other fields in your query?
Geert
-
The error is a database error, not an XmlDom error, so it should be something on the database side.
EA does some pre-processing with the SQL's we send trough, so it might be related to that. I would really look into the dbError.txt and what you can see on the profiler.
Might not be related, but if you are only interested in the DiagramID, why are you returning all those other fields in your query?
Geert
Thank you Geert.
I can't access %appdata%, I don't have Sparx Systems folder locally. I will contact the IT-dep.
I just wanted to see what objects I get out, and I know that with the names not the IDs. I can remove them, do you think it will make a difference though?
-
From DBError.txt:
2017-10-30 09:23:22
Microsoft OLE DB Provider for SQL Server [-2147217900]
Invalid column name 'undefined'.
Context:
SELECT o.ea_guid AS CLASSGUID, o.Object_Type AS CLASSTYPE, o.Name AS Name, d.Name AS Diagram, d.Diagram_ID AS DiagramID
FROM t_object o
INNER JOIN t_diagramobjects do ON do.Object_ID = o.Object_ID
INNER JOIN t_diagram d ON d.Diagram_ID = do.Diagram_ID
WHERE o.Object_ID = undefined
ORDER BY Diagram
It seems that objectID = undefined. Although, as I mentioned earlier it seems to run the script twice. Once with objectID = undefined and once with correct objectID, since I get the correct report output.
I have no idea how to backtrack this error. Is it in a script, function, template or fragment? :o
Thanks for your help!
-
"undefined" is what you will get from VBScript from an uninitialized variable.
-
Do you still have a "main" call in your script?
That would explain this behavior.
The function would indeed be executed twice. Once when loading the script (evaluating a script actually executes it) and once when running the report.
Geert
-
Thank you for all the help!
I have another question regarding using a generated report as attachment or appendix in another report. I have created another thread for this, feel free to have a look!
Thanks again!
New thread (http://www.sparxsystems.com/forums/smf/index.php/topic,38819.0.html)