Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Viking 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.
-
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
-
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.
-
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
-
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.
-
In the past I've used this workaround to get the actual image from a diagram:
/// <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
-
Hello,
I am trying to use the script above in Word resp. in VBA.
I am new to VBA. I cannot find MemoryStream.
Can somebofy tell me, how I can link MemoryStream to my code resp. which library I have to reference?
Many thanks in advance, V.
-
MemoryStream is a .Net class. I don't know VBA well enough to know if there is an equivalent class (or set of functions) available in VBA.
-
How about entering "vba memorystream" into Google? That seemed to give promising results.
q.
-
I identified it. I had to reference mscorlib.dll. Many thanks.
-
Hi,
(1)
Could somebody tell me, why it is better to use PutDiagramImageOnClipboard instead of PutDiagramImageToFile? Is it just because of working memory?
(2)
I got the half of Geerts example to work in VBA. I do not find an equivalent in VBA for the code below (see also Simons comment). Does anybody know the solution?
MemoryStream imageStream = new MemoryStream(File.ReadAllBytes(filename));
Image diagramImage = Image.FromStream(imageStream);
System.IO.File.Delete(filename);
Many thanks in advance, V.
-
(1) the clipboard does not need file operations and thus is (a lot) faster.
q.
-
Hello,
I am trying to use the script above in Word resp. in VBA.
I am new to VBA. I cannot find MemoryStream.
Can somebofy tell me, how I can link MemoryStream to my code resp. which library I have to reference?
Many thanks in advance, V.
Hi Viking
If you need to insert images to word (without memory stream )then you can try using below codes
Selection.InlineShapes.AddPicture FileName:= _"fullPathOftheImage", LinkToFile:=False, _SaveWithDocument:=True
or
objShapes.AddPicture (fullPathOftheImage)
Thanks
Arshad
-
(1)
Could somebody tell me, why it is better to use PutDiagramImageOnClipboard to PutDiagramImageToFile? Is it just because of working memory?
I don't think it's better, I think it's much worse. I hate it when programs hijack my clipboard. >:(
But it might indeed be faster then using the file approach.
Geert
-
Hi Viking
If you need to insert images to word (without memory stream )then you can try using below codes
Selection.InlineShapes.AddPicture FileName:= _"fullPathOftheImage", LinkToFile:=False, _SaveWithDocument:=True
or
objShapes.AddPicture (fullPathOftheImage)
Thanks
Arshad
Thank you, Arshad. That worked.
-
Hi Viking
If you need to insert images to word (without memory stream )then you can try using below codes
Selection.InlineShapes.AddPicture FileName:= _"fullPathOftheImage", LinkToFile:=False, _SaveWithDocument:=True
or
objShapes.AddPicture (fullPathOftheImage)
Thanks
Arshad
Thank you, Arshad. That worked.
Cheers ;D ;D
Arshad