Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Daiim on May 02, 2022, 04:50:38 am
-
Hi everyone,
I try to access an embedded file (internal artifact) from code to read it's content. But sadly I can not find an approach how to do this.
The EA.Element has an property "IsInternalDocArtifact" but this is 'false' for my element. I also tried to access the "MiscData(0..)" property but got nothing.
The first approach was to acces the Files collection of the element but this is empty, too.
A workaround is to add it's content to a linked document but that seems to be confusing, as the file is opened via double click on the diagram element, so the data must be somewhere.
Any ideas?
Daniel
-
It's in t_document linked via ElementID. The binContent holds the zip with a single file str.dat. repository.sqlquery will return that as base64 encoded data.
Not sure whether the API meanwhile offers more comfort. I guess not. There are a couple of threads here that detail the procedure. Try looking for "str.dat" or anything else mentioned above.
q.
-
Thank you for this hint. This is a good point to start but it seems to be quite tough to implement with jscript, so I'll use the workaround for the first shot. Maybe I can find some time to figure out how to directly access the content with jscript later.
-
Can't speak for that J-stuff but it's not rocket science. So there should be libs to deal with base64 as well as zip files. Good luck anyway.
q.
-
Is there a way to load external libraries from inside EA scripting environment?
-
I hope I'm not late for the party, but there is a solution using the decodeBase64zippedXML() function of the Geert's framework (https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/tree/master (https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/tree/master)). In the example below I'm using another lib for parsing a JSON stored as a content of the artifact element. (For the JSONClass see https://gist.github.com/t3rminus/d278175893dea1ecfed83c29df56a9d8#file-vbsjson-vb (https://gist.github.com/t3rminus/d278175893dea1ecfed83c29df56a9d8#file-vbsjson-vb)).
option explicit
!INC Local Scripts.EAConstants-VBScript
!INC Tools.JSONClass
!INC Utils.Include
sub main
' get the content from DB
dim sql
sql = "select BinContent from t_document where DocName = 'data.json'"
dim result
result = Repository.SQLQuery(sql)
dim JSON, configJSON, config
' b64 decode and unzip
configJSON = decodeBase64zippedXML(result, "BinContent")
set JSON = new vbsJSON
' decode JSON
set config = JSON.decode(configJSON)
' use the data
' ...
end sub
main
(I've spent some time trying to find the solution, so I hope this might help someone.)