Export diagram as image

Hi,
Is it (or will it be) possible to export a diagram created with a DSL as an image just like the Visual Studio Class Designer does?
If not, how could I implement it?
Thanks!
Mike
[197 byte] By [MikeLapierre] at [2007-12-16]
# 1

First, I must give the caveat that we're working through our API design at the moment, so all of this is subject to change, it's only a CTP at this point, etc.

That said, the core functionality used by the Class Designer is currently available via the Microsoft.VisualStudio.Modeling.Diagrams.Diagram.CreateBitmap() API. Given an instance of your diagram, you can make this call, passing in a collection of shapes (or the collection Diagram.NestedChildShapes if you want to include all shapes on the diagram), and it will return a Bitmap object which you can choose to save to a file, place on the clipboard, etc.

If you want something even closer to the Class Designer experience, there is a class called Microsoft.VisualStudio.EnterpriseTools.Shell.DiagramExporter, in the assembly Microsoft.VisualStudio.Modeling.Sdk.Shell.dll (already referenced from your Designer project if you created a solution via the DSL designer wizard). You can construct an instance of this class given an object that implements IServiceProvider, and then it is just a matter of calling DiagramExporter.ExportDiagram (or ExportDiagrams to do multiple diagrams at once). This takes a path (paths) to your diagram file(s), the directory on disk you where you want the diagrams exported, the image format you want to use, and a boolean value indicating whether existing diagrams should be overwritten.

I know I've left some things a little vague in this explanation, if you try to use these classes and you can't figure something out, let me know.

Thanks,
Grayson Myers [MSFT]

GraysonMyersMSFT at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 2
Thanks for the great info!
The first technique (CreateBitmap) works great.
I just have a little quesion about the second technique...
Do i have to create my own object that implements the IServiceProvider?
I have tried passing the ServiceProvider property of CommandSet object but it only closes the diagram without exporting it...
Mike
MikeLapierre at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 3
In theory, the IServiceProvider passed to the CommandSet should work just fine. I just tried this with the same results as you got, though. Unfortunately there's a bug here that's preventing the DiagramExporter class from working with designers created using the DSL tools. Please feel free to log this in the MSDN product feedback center, then you'll be able to track progress.

In the meantime, you can continue to use the first method.

Thanks,
Grayson

GraysonMyersMSFT at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 4

Hi Grayson,

I need to generate a .cd file and convert it to a class diagram image programatically. I investigated anything I could find on the web related to Microsoft.VisualStudio and its sub namespace and classes.

Can you please guide me how to achieve a proper ClassDiagram object from the .cd (xml) file? (something that I can just call its CreateBitmap method...)

I really appreciate your help.

Regards

Paymon

info@paymon.net

Paymon at 2007-9-8 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...

Visual Studio

Site Classified