Export diagram as image
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
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]
In the meantime, you can continue to use the first method.
Thanks,
Grayson
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