locked
How to generate a DBML image file (jpg, png, etc...) without launching VS (in other words, automated), using C#?? RRS feed

  • Question

  • I'd like to reach into a project, any project type that contains a DBML file, and generate an image (the same image generated by the DBML design surface editor) of that file and save it out to a JPG or TIFF or PNG, etc...

    I've seen this: http://blogs.msdn.com/b/camerons/archive/2010/03/08/save-a-diagram-to-image-file.aspx

    But if I understand that correctly, that just adds a menu item so you can save the DBML as a file, manual intervention necessary.

    I want to perform this completely automated.

    The other sample I saw was for generating images but from a specific project type in VS 10. I need to do this for any DBML in any project type.

    Is this possible, can anyone point me to some sample code?

     

    Thank you!


    --ACG
    Wednesday, December 7, 2011 6:31 PM

Answers

  • Hi ACG,

     

    The major automation logic used in your mentioned blog is to use IDiagramContext..::.CurrentDiagram to export a bitmap object and save the object to the file.

     

    In general, we can this type by declaring an Imported property DiagramContext in a UML extension. we also can obtain the IDiagramContext object by casting a EnvDTE.ProjectItem  if the item is a UML Diagram.

     

    Therefore, we can write an add-in to check the kind of the ProjectItem, cast UML project item to IDiagramContext object  and save image to a bitmap for any project. Of cause, all the progress are to automate the VS IDE and will run in a VS instance.

     

    Since the projectitem has a hierarchy structure. You may write a recursive call to go through all projectitems of a project. For more information about accessing project items, please check Accessing Project Type Specific Project, Project Item, and Configuration Properties.

     

    Since generate a DBML image is specific to Visual Studio Visualization & Modeling, I suggest you visit Visual Studio Visualization & Modeling SDK forum for the extension of UML diagram extension.

     

    Hope the information helps,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by Yi Feng Li Thursday, December 15, 2011 9:03 AM
    Thursday, December 8, 2011 3:12 AM

All replies

  • Hi ACG,

     

    The major automation logic used in your mentioned blog is to use IDiagramContext..::.CurrentDiagram to export a bitmap object and save the object to the file.

     

    In general, we can this type by declaring an Imported property DiagramContext in a UML extension. we also can obtain the IDiagramContext object by casting a EnvDTE.ProjectItem  if the item is a UML Diagram.

     

    Therefore, we can write an add-in to check the kind of the ProjectItem, cast UML project item to IDiagramContext object  and save image to a bitmap for any project. Of cause, all the progress are to automate the VS IDE and will run in a VS instance.

     

    Since the projectitem has a hierarchy structure. You may write a recursive call to go through all projectitems of a project. For more information about accessing project items, please check Accessing Project Type Specific Project, Project Item, and Configuration Properties.

     

    Since generate a DBML image is specific to Visual Studio Visualization & Modeling, I suggest you visit Visual Studio Visualization & Modeling SDK forum for the extension of UML diagram extension.

     

    Hope the information helps,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by Yi Feng Li Thursday, December 15, 2011 9:03 AM
    Thursday, December 8, 2011 3:12 AM
  • Hello

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Monday, December 12, 2011 2:59 AM