Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: survex on May 08, 2015, 10:53:51 pm

Title: Add image to diagram via scripting
Post by: survex 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?
Title: Re: Add image to diagram via scripting
Post by: Geert Bellekens 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
Title: Re: Add image to diagram via scripting
Post by: survex 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.
Title: Re: Add image to diagram via scripting
Post by: Geert Bellekens 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
Title: Re: Add image to diagram via scripting
Post by: qwerty 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.
Title: Re: Add image to diagram via scripting
Post by: survex on May 09, 2015, 03:02:41 am
That's the main trick - how to add image to t_image table?
Title: Re: Add image to diagram via scripting
Post by: qwerty 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.
Title: Re: Add image to diagram via scripting
Post by: survex 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?
Title: Re: Add image to diagram via scripting
Post by: qwerty 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
Title: Re: Add image to diagram via scripting
Post by: Geert Bellekens on May 09, 2015, 04:03:15 pm
You should really try this (http://lmgtfy.com/?q=how+to+insert+image+in+access+database+using+sql)

Geert
Title: Re: Add image to diagram via scripting
Post by: survex 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.
Title: Re: Add image to diagram via scripting
Post by: qwerty 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.
Title: Re: Add image to diagram via scripting
Post by: Geert Bellekens 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
Title: Re: Add image to diagram via scripting
Post by: survex 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      

 >:(
Title: Re: Add image to diagram via scripting
Post by: survex on May 09, 2015, 10:58:39 pm
Looking for a way to insert base64 encoded data without MS-Access internal base64 encoding.
Title: Re: Add image to diagram via scripting
Post by: qwerty on May 09, 2015, 11:29:18 pm
You will need binding since you can not (easily) insert blob data with a plain SQL. For the base64 encoding you'll probably find some lib as well.

q.