Book a Demo

Author Topic: Adding an Alternate Image to Element  (Read 5402 times)

Brian L

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Adding an Alternate Image to Element
« on: January 29, 2014, 03:52:08 am »
I am trying to add an image to an element through the automatic interface.
Does anyone know the method to superimpose an image onto an element?

Thank you for your help,
Brian

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #1 on: January 29, 2014, 05:09:35 am »
You need to add the string "ImageID=<num>;" to the diagram-object style. <num> is the id from the image table t_images.

q.

Brian L

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #2 on: January 29, 2014, 05:30:25 am »
Okay. Thanks.
I will try that!

Brian L

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #3 on: January 29, 2014, 05:40:10 am »
Okay.
It looks like I can use SetStyleEx on the DiagramObject to add "ImageID=<num>;"

Is there a way to automatically add images to they system to reference?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #4 on: January 29, 2014, 06:19:42 am »
You can import reference data with an anyway undocumented method
Code: [Select]
Repository.CustomCommand ("Repository", "ImportRefData", <xml>); or you hack them using a SQL script. IIRC there's still a glitch when importing refdata so IDs will not be kept and assigned newly (and wrongly) during the import. I once wrote a Perl script to import images (and other refdata) correctly.

q.

Brian L

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #5 on: January 31, 2014, 04:13:36 am »
Okay.

I was able to create a vbscript to generate an xml file with images from a folder.  I was then able to import the xml string using your custom command.  Now I am able to change the diagram object's appearance with an imported image.

I didn't see the command in your ScriptingEA book until you pointed it out. I saw in the book that the xml needs to be a string.

Thank you q!
I really appreciated your help.

-Brian

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #6 on: January 31, 2014, 05:02:52 am »
No worries. I even forget some of the basic methods of the API sometimes :-) If we all were Mozart we would not need documentation. It would all be in our mind. But we normal humans have to fight with reading all the time...

q.

Brian L

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #7 on: January 31, 2014, 05:28:26 am »
haha so true

But I find that your books have helped me along with much of my scripting with EA.

Veleane

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #8 on: May 20, 2014, 12:34:35 am »
Hi all,

Does anyone have a vbscript to load image files (from a folder) into the EA repository (by using reference data import) ?

Thanks a lot!

Olivier


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #9 on: May 20, 2014, 02:21:01 am »
I once hacked the following in Perl:
Code: [Select]
use strict;
no strict 'refs';
use Win32::OLE qw (in);
use XML::Simple;
use MIME::Base64 ();
use DBI;

#use EaSimulator;
#EaSimulator->new ({'PACKAGE'=>"{088A0FC2-E1E4-41d8-9661-900C18E2243D}"});

my %tableData =
  ('t_image' => {PRIMARY => 'ImageID', COLUMNS => ['Type', 'Name', 'ImageID', 'Image']},
   't_propertytypes' => {PRIMARY => 'Property', COLUMNS => ['Property', 'Description', 'Notes']},
   't_statustypes' => {PRIMARY => 'Status', COLUMNS => ['Status', 'Description']});

my $rep = $ENV{'REP'};

my $dbName = $rep->ConnectionString;
my $dbi;
if ($dbName =~ /\.eap$/i) { $dbi = "dbi:ADO:Data Source=$dbName;Provider=Microsoft.Jet.OLEDB.4.0" }
elsif ($dbName =~ /Data Source=([^;]*)/) { $dbi = "dbi:ODBC:$1" }
else { die "can not figure out DB type from $dbName" }
my $dbh = DBI->connect($dbi, "") or die "Can't connect to $dbi";

my $fn = $rep->xmiPath($rep->GetTreeSelectedObject()) . 'RefData.xml';

my $xs = XML::Simple->new(); # convert the XML return string into a hash
my $ref = $xs->XMLin($fn);

for my $key (keys %{$ref->{'DataSet'}}) {
  import ($ref->{'DataSet'}->{$key});
}

return 1;

sub import {
  my $data = shift;
  my $table = $data->{'table'};
  my $primary = $tableData{$table}->{PRIMARY} or return;

  my %xref;
  my $columns = "`" . join ("`, `", @{$tableData{$table}->{COLUMNS}}) . "`";
  my $sth;
  $sth = $dbh->prepare("delete * from $table where 1");
  $sth->execute();

  if (ref ($data->{'DataRow'}) eq "HASH") {
    $data->{'DataRow'} = [$data->{'DataRow'}];
  }
  for (in @{$data->{'DataRow'}}) {
    my $row = $_->{ 'Column'};
    next if $#{$tableData{$table}->{COLUMNS}} < 0;
    my $sql;

    $sql = "INSERT INTO $table (";
    my $values = "";
    my $sep = "";
    for my $col (@{$tableData{$table}->{COLUMNS}}) {
      if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
        $values .= $sep . '?';
      } else {
        next unless $row->{$col}->{'value'};
        $values .= $sep . quote ($row->{$col}->{'value'});
      }
      $sql .= "$sep`$col`";
      $sep = ", ";
    }
    $sql .= ") VALUES ($values)";
    $sth = $dbh->prepare($sql);
    my $param = 0;
    for my $col (@{$tableData{$table}->{COLUMNS}}) {
      if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
        $param++;
        $sth->bind_param($param, MIME::Base64::decode($row->{$col}->{'content'}), DBI::SQL_BLOB);
      }
    }
    $sth->execute();
  }
}

sub quote {
  $_ = shift();
  s/'/''/gm;
  s/‰/&auml;/gm;
  s/ˆ/&ouml;/gm;
  s/¸/&uuml;/gm;
  s/ƒ/&Auml;/gm;
  s/÷/&Ouml;/gm;
  s/‹/&Uuml;/gm;
  s/[ch64258]/&szlig;/gm;
  return "'$_'";
}
I know that for a VB programmer it looks as if an armadillo has been rolled over the keyboard, but it's all I have.

q.

Veleane

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Adding an Alternate Image to Element
« Reply #10 on: May 20, 2014, 05:01:38 pm »
Thanks Brian!

Olivier