Author Topic: Bulk Import of Alternative Images  (Read 9292 times)

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1323
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Bulk Import of Alternative Images
« on: January 16, 2019, 02:42:56 pm »
We need to bulk import lots of alternative images (png format) into Sparx EA model. The only way I can see of doing this at present is to select all the image files from file explorer  and drag them onto a diagram. Unfortunately the images are then named image1, image2, etc rather than using the file name.
Does anyone know of another way where the file name is used to the name the image?

We are using EA V14.1 Build 1427

Was thinking of maybe writing some code but couldn't see an API to import an image file into t_image table. Is there something I've missed?

Happy to help
:)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #1 on: January 16, 2019, 11:33:41 pm »
You could create a file which is used for reference date ex-/import. Alternatively you can go directly to the database (just store the image as blob).

q.

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1323
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #2 on: January 18, 2019, 04:36:14 am »
Thanks Qwerty.
Will look into those options.
Happy to help
:)

steen.jensen

  • EA User
  • **
  • Posts: 181
  • Karma: +8/-1
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #3 on: January 18, 2019, 08:24:05 am »
please reply how this xml file should look like for import as referens data, or if there are any documentation for that in online doc that I havent found yet  :-[

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #4 on: January 18, 2019, 08:31:55 am »
Actually it's quite simple. Create it from EA with export ref data. The pictures are store as base64-encoded blobs. For simplicity use a dummy model with a single picture.

q.

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1323
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #5 on: January 22, 2019, 05:37:37 pm »
Okay for future reference this is how I did it.
From file explorer I sorted the image files (PNG) in order by name then selected them all and dragged them onto a diagram in Sparx EA. This imported all the images but named them image1, image2, etc
Next I opened a cmd dialog and typed dir /b > directory.csv. This gave a file with all the files names.
Then open the file directory.csv with excel. I them copied Image text into the 2nd column and the in the 3rd column put a formula "C1+1" and copied the formula down the column so it had a seqence 1,2,3 etc.
One last step was to open up the Directory.csv file in notepad and replaced "Image," with "Image". Now have file with two columns. The first columan is the file name and the 2nd has Image1, Image2 etc.
Next I imported the CVS into the eapx file using MS Access. The new table was called Directory.
I then ran the following SQL to update t_image.Name with the filename
Code: [Select]
UPDATE t_image
INNER JOIN Directory ON t_image.Name = Directory.Image
SET t_image.Name = [Directory].[FileName];
Now have all the images with filenames in t_image table.
A bit cumbersome but it was better then importing each image one at a time. Had about 400 images.
Happy to help
:)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #6 on: January 22, 2019, 06:11:19 pm »
Okay for future reference this is how I did it.
[SNIP]
Cute!

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #7 on: January 22, 2019, 07:01:07 pm »
Honestly I'd written a short script to create according INSERT statements from a directory containing the pictures. Shouldn't take more than half an hour.

q.

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1323
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #8 on: January 26, 2019, 09:41:52 am »
Honestly I'd written a short script to create according INSERT statements from a directory containing the pictures. Shouldn't take more than half an hour.

q.
Yeah I was tempted to do that but couldn't be arsed that day to figure out how to store and encode the image into the t_image table.
My approach took about 15 min. If I have to import images on a regular basis I might put the effort in to a script.
Happy to help
:)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #9 on: January 26, 2019, 07:13:43 pm »
The images are just stored as blob (png).

q.

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #10 on: January 28, 2019, 07:57:32 am »
Now have you exported them as reference data, as a back up?

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1323
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #11 on: January 28, 2019, 01:38:44 pm »
Now have you exported them as reference data, as a back up?
No I've got them stored in the eapx file and that is backed. I've since exported them to an MDG and put that in our EA Config folder for everyone to use in our enterprise repository.
Happy to help
:)

steen.jensen

  • EA User
  • **
  • Posts: 181
  • Karma: +8/-1
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #12 on: January 29, 2019, 09:28:04 am »
Hmm One way of get the work done is like this: (EA v 14.1)
Create a package with name "Icons" for example and create a empty diagram.
Select a bunch of icons, drag them to the diagram, Select "Image asset"
Select Layout/Diagram layout/Box then all pictures are nicely placed on the diagram.

In any other diagram, select an element that you want to have an alternate picture on, select "Image asset as Alternate picture"
Now you can select any package/folder in your project, preferably the "Icons" package, there select any of your new icons
voilĂ 
Works for me

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #13 on: January 29, 2019, 11:20:38 am »
Just want to support the suggestion of using Image Artifacts instead of adding images to the t_image table.

When you select image asset when dropping the files, it already uses the filenames as the element name. A quick script could remove the extensions.

Once you've done this, you can organize and manage these elements however needed. Expect us to be doing more with these in the future. We already have drag and drop offering to apply the image or add a new element with that image in our next version. How would you like to work with them?

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1323
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Bulk Import of Alternative Images
« Reply #14 on: January 30, 2019, 04:57:43 pm »
Thanks for the suggestion of using Image Artifacts. I'll bear that in mind in the future.

I see a problem with that suggestion though as it puts image artifacts in the model and pollutes it with stuff that is not relevant to the subject at hand. i.e. the image artifacts have nothing to do with what I'm modelling. I just need to use alternative images in some diagrams so I can present the same concepts to some less technical folk like managers and executives.

I guess I could live with it though by putting the image artifacts into the same top level package as I put model documents.

I'll have a try with image artifacts and see if they works for me.
Happy to help
:)