Author Topic: Add image to diagram via scripting  (Read 9268 times)

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Add image to diagram via scripting
« on: May 08, 2015, 10:53:51 pm »
Is there any way to add image to diagram?
The main problem is to add image to Image Manager, because I don't know how to add image to diagram without adding it to Image Manager.

Has anyone code snippet solving this problem?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add image to diagram via scripting
« Reply #1 on: May 08, 2015, 11:07:29 pm »
If you copy an image you can paste it to a diagram using Ctrl-Shift-Insert
It looks like it creates a boundary with this image as appearance.

I'm sure there's a way to simulate the same using a script. (if needed by updating the database directly)

Geert

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Re: Add image to diagram via scripting
« Reply #2 on: May 08, 2015, 11:19:09 pm »
When you add image to diagram by pasting one new record added to t_image table like:

ImageID;Name;Type;Image;
1585110939;Image70166;Bitmap; ;

EA somehow stores image internally (no external image file) and I don't have any clue how to add image to EA.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add image to diagram via scripting
« Reply #3 on: May 08, 2015, 11:51:16 pm »
I guess you somehow have to store the binary blob of the image in the t_image.Image column.
Seems like pretty standard stuff so you should be able to find something on google.

Geert
« Last Edit: May 08, 2015, 11:51:34 pm by Geert.Bellekens »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Add image to diagram via scripting
« Reply #4 on: May 09, 2015, 12:36:00 am »
You need to have the image in t_image (Settings/Images or where ever the menu might be), then add a boundary to a diagram and assign it an alternate image with the id of this very image in t_image.

q.

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Re: Add image to diagram via scripting
« Reply #5 on: May 09, 2015, 03:02:41 am »
That's the main trick - how to add image to t_image table?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Add image to diagram via scripting
« Reply #6 on: May 09, 2015, 03:15:26 am »
Funny that similar threads appear one after the other:
http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1431104354

q.

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Re: Add image to diagram via scripting
« Reply #7 on: May 09, 2015, 03:24:44 am »
Ok,
I'm reading image file like:
    var fso = new ActiveXObject("Scripting.FileSystemObject");
      f = fso.OpenTextFile("Z:\\home\\survex\\Desktop\\chart2.php.png", 1);
    // Read from the file and display the results.
    while (!f.AtEndOfStream)
    {
        var r = f.ReadLine();
        Session.Output(r);
    }

    f.Close();

and getting byte symbols:
‰PNG      
     
EEE[ch1041]v[ch1038][ch1083][ch1059][ch1073]M[ch1086][ch1060]…N[ch1085][ch1112][ch1063][ch1114]8q"))i[ch1040][ch1026]”d[ch1055][ch1115]=^”3p[ch1072][ch1040]„„„[ch1042][ch1042][ch1042]#...

while t_image contains image like ASCII stream:
89g8CIEkQhIjgkAQ3WCMDyQq2FpEwTYWrCJWrBAsIloQFYtN5VUf/GwNYKFiFEVRo1IqBaxE
EAOS4IOHBAhLAgkBQh6bxz5nfn9MMpmdnZmd2cw+kpzvZz9h9txz7j07ey9n5547d4isrCxA
...

How can I convert one to another to INSERT it to database?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Add image to diagram via scripting
« Reply #8 on: May 09, 2015, 05:21:13 am »
I don't know how to handle this with your language. When I'm using Perl I use a DB driver that allows parameters like
Code: [Select]
INSERT INTO table (Col) VALUES (?)and then I bind that to the blob.

t_image.image should hold the same binary data. I posted here something related how to handle it.

q.

P.S. http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1390927928/9#9
« Last Edit: May 09, 2015, 05:28:43 am by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add image to diagram via scripting
« Reply #9 on: May 09, 2015, 04:03:15 pm »
You should really try this

Geert

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Re: Add image to diagram via scripting
« Reply #10 on: May 09, 2015, 08:24:13 pm »
Geert, pretty offensive comment... Google gives no answer how to add image to MS-Access via JScript.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Add image to diagram via scripting
« Reply #11 on: May 09, 2015, 08:39:44 pm »
Actually if you google for OLEDB JSCRIPT (after Geert's LMGTFY) you will find this: https://msdn.microsoft.com/en-us/library/aa325887(v=vs.71).aspx

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add image to diagram via scripting
« Reply #12 on: May 09, 2015, 09:06:59 pm »
Quote
Geert, pretty offensive comment... Google gives no answer how to add image to MS-Access via JScript.
It is not meant as offensive, but as helpful; with a wink.
The reason I'm posting it is because the problem you have right now is not specific to EA, and I'm sure you can find the answer if you google a bit.

Geert

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Re: Add image to diagram via scripting
« Reply #13 on: May 09, 2015, 10:57:08 pm »
The current problem is:
t_image.Image is field of type bin.base64, so all data being inserted in table has base64 encode transformation:
UPDATE t_image SET Image = 'abcdabcd';
   and
SELECT * FROM t_image => YWJjZGFiY2Q=

Trying to insert image byte data via JScript I'm getting following error:
DAO.Database [3075]

Syntax error in string in query expression ''‰PNG
'., Line:95      

 >:(

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Re: Add image to diagram via scripting
« Reply #14 on: May 09, 2015, 10:58:39 pm »
Looking for a way to insert base64 encoded data without MS-Access internal base64 encoding.