Author Topic: MS Word + VBScript to import EA diagrams  (Read 151 times)

Viking

  • EA User
  • **
  • Posts: 220
  • Karma: +1/-2
    • View Profile
MS Word + VBScript to import EA diagrams
« on: November 25, 2017, 06:37:32 am »
Hello,
I am quite sure that it exists already.
I am looking for a script (VBScript), that replaces keyword (resp. appropriate search-statements) in MS Word with Sparx EA diagrams.
In other words, I write a document with Word and add keywords, which will be replaced by diagrams out of EA, as soon as I start the script.
Thank you very much in advance for your feedback, V.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7727
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: MS Word + VBScript to import EA diagrams
« Reply #1 on: November 25, 2017, 05:44:51 pm »
I don't have anything like that.

But it seems simple enough. If you can't find anything you can always ask one of the EA consultants (like myself) on the forum to write it for you.

Geert

Viking

  • EA User
  • **
  • Posts: 220
  • Karma: +1/-2
    • View Profile
Re: MS Word + VBScript to import EA diagrams
« Reply #2 on: December 06, 2017, 03:34:05 am »
I wonder if it possible to retrieve a diagram (as a picture) from Word using the Sparx Object Model. I did not find anything but an addin using the clipboard.

It would be could if no installation would be required.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7727
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: MS Word + VBScript to import EA diagrams
« Reply #3 on: December 06, 2017, 03:54:10 am »
Do you want to retrieve a diagram image from EA and use it in Word, or get an image from Word and put it in EA?

For the first one you can use EA.Repository.PutDiagramImageToFile ()

Geert

Viking

  • EA User
  • **
  • Posts: 220
  • Karma: +1/-2
    • View Profile
Re: MS Word + VBScript to import EA diagrams
« Reply #4 on: December 06, 2017, 05:47:04 pm »
Do you want to

(1) retrieve a diagram image from EA and use it in Word, or
(2) get an image from Word and put it in EA?

For the first one you can use EA.Repository.PutDiagramImageToFile ()

Geert

I want to do (1). Thank you very much for your help.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7727
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: MS Word + VBScript to import EA diagrams
« Reply #5 on: December 06, 2017, 05:55:36 pm »
In the past I've used this workaround to get the actual image from a diagram:
Code: [Select]
/// <summary>
/// returns diagram image
/// </summary>
public Image image
{
    get
    {
        EA.Project projectInterface = this.model.getWrappedModel().GetProjectInterface();
        string diagramGUID = projectInterface.GUIDtoXML(this.wrappedDiagram.DiagramGUID);
        string filename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
        //save diagram image to file (format ".png")
        projectInterface.PutDiagramImageToFile(diagramGUID, filename, 1);
        //load the contents of the file into a memorystream
        MemoryStream imageStream = new MemoryStream(File.ReadAllBytes(filename));
        //then create the image from the memorystream.
        //this allows us to delete the temporary file right after loading it.
        //When using Image.FromFile the file would have been locked for the lifetime of the Image
        Image diagramImage = Image.FromStream(imageStream);
        //delete the temorary file
        System.IO.File.Delete(filename);

        return diagramImage;
    }
}
Geert