Microsoft Developer Network > Форумы > Visual Studio Extensibility > Get the Shape Element from the Model Element in my Template

Отвечено Get the Shape Element from the Model Element in my Template

  • 23 апреля 2007 г. 14:23
     
     
    Hi,
    I'm trying to obtain the shape element from a model element in my T4 template. Indeed, I would like to create a XML file wich describe all my model elements but with some graphics information like position and size.
    I found some topics about my problem but unfortunately, I don't succeed in it.

    You can see my test :

    Code Snippet

    // entity is an instance of my model class Entity

    // I want to obtain the shape which represents my entity element

    LinkedElementCollection<ElementPresentation> shapes = PresentationViewsSubject.getPresentation(entity);


    But the result of this operation gives me "NULL".
    However, I use this method during one of my rule and it works fine.  I don't understand why it doesn't work in my template... Sad

    Thanks for your answer!
    Best regards

    ps : And sorry for my english ^^

Ответы

  • 23 апреля 2007 г. 15:45
    Модератор
     
     Отвечено

    Hi there,

    The reason it works in a rule but not in the template is as follows: the model information is saved in two file, MyFile.XXX and MyFile.XXX.diagram, where XXX is the file extension you have chosen for your language. MyFile.XXX contains the data for the non-shape related elements the user has created, and MyFile.XXX.diagram contains the data for the shapes.

     

    When the designer loads a model, it loads both files. By default, the directive processor generated for your language that is used by the T4 engine to load your models will only load MyFile.XXX, so the shape information isn't available.

     

    Fortunately, there is a simple way to change this default behaviour.  In the "Dsl" project, add a new partial class called [YourLangauge]DirectiveProcessor and provide an override of the "LoadDiagramData" property that returns true. This should make the shape information available when you run the T4 template.

     

    Duncan

Все ответы

  • 23 апреля 2007 г. 15:45
    Модератор
     
     Отвечено

    Hi there,

    The reason it works in a rule but not in the template is as follows: the model information is saved in two file, MyFile.XXX and MyFile.XXX.diagram, where XXX is the file extension you have chosen for your language. MyFile.XXX contains the data for the non-shape related elements the user has created, and MyFile.XXX.diagram contains the data for the shapes.

     

    When the designer loads a model, it loads both files. By default, the directive processor generated for your language that is used by the T4 engine to load your models will only load MyFile.XXX, so the shape information isn't available.

     

    Fortunately, there is a simple way to change this default behaviour.  In the "Dsl" project, add a new partial class called [YourLangauge]DirectiveProcessor and provide an override of the "LoadDiagramData" property that returns true. This should make the shape information available when you run the T4 template.

     

    Duncan

  • 24 апреля 2007 г. 7:48
     
     
    Thanks a lot Duncan ! It works fine.
    I don't believe I could find this solution alone... Smile