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
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...)
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.
I would like to write a small add-in for Visual Studio to automaticly export all diagrams as images. I have read a lot of interesting things on this post, but I have a problem with both classes DiagramExporter and Diagram (CreateBitmap).
In an add-in, can I have a IServiceProvider need in DiagramExporter constructor
How can I retreive a Diagram object (abstract class)
If you have some example of code, it will be very nice.
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
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.
How to Export diagram as image
quoi
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
kieronlanning
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]
dmcrews4202
Hi All,
I would like to write a small add-in for Visual Studio to automaticly export all diagrams as images. I have read a lot of interesting things on this post, but I have a problem with both classes DiagramExporter and Diagram (CreateBitmap).
In an add-in, can I have a IServiceProvider need in DiagramExporter constructor
How can I retreive a Diagram object (abstract class)
If you have some example of code, it will be very nice.
Thanks in advance for your help.
Francois.
brengarne
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
n9986
In the meantime, you can continue to use the first method.
Thanks,
Grayson