Author Topic: Access content of an Artifact (Internal) with scripts  (Read 3777 times)

Daiim

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-0
    • View Profile
Access content of an Artifact (Internal) with scripts
« 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

« Last Edit: May 02, 2022, 06:24:36 am by Daiim »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Access content of an Artifact (Internal) with scripts
« Reply #1 on: May 02, 2022, 07:50:19 am »
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.

Daiim

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-0
    • View Profile
Re: Access content of an Artifact (Internal) with scripts
« Reply #2 on: May 02, 2022, 07:19:11 pm »
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.


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Access content of an Artifact (Internal) with scripts
« Reply #3 on: May 02, 2022, 11:22:04 pm »
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.

Daiim

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-0
    • View Profile
Re: Access content of an Artifact (Internal) with scripts
« Reply #4 on: May 16, 2022, 08:51:18 pm »
Is there a way to load external libraries from inside EA scripting environment?

rnovicky

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Access content of an Artifact (Internal) with scripts
« Reply #5 on: January 25, 2025, 09:22:08 pm »
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). 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).

Code: [Select]
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.)