Pablo Galiano : Wednesday, August 20, 2008 - Posts

Subscriptions

<December 2008>
SuMoTuWeThFrSa
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

News

Subscribe to Pablo Galiano by Email

Post Categories

Wednesday, August 20, 2008 - Posts

How do I get the model element associated to a shape and vice versa

My sixth How do I is up.

Scenario

The scenario here is really simple, we want to get the shape associated with a model element or vice versa. The focus of this How do I tackles this scenario.

 

Interfaces and classes needed

 

Code snippet

Getting the model element corresponding shape:

 

    PresentationViewsSubject.GetPresentation(modelElement)

        .ForEach(pel =>

            {

                ShapeElement shape = pel as ShapeElement;

 

                //TODO: use shape

            });

Getting the model element corresponding shape:

 

    ModelElement modelElement = PresentationViewsSubject.GetSubject(shape);

 

    //TODO: use model element

 

Assemblies needed

  • Microsoft.VisualStudio.Modeling.Sdk.Diagrams

 

Stay tuned,

Pablo

posted Wednesday, August 20, 2008 11:55 AM by pga with 1 Comments

How do I flush content to the Visual Studio output window

My fifth How do I is up.

Scenario

Every time that we write to the Visual Studio output window, the content is not flushed automatically. Sometimes this can be resolved by the Application.DoEvents(); call. But this method doesn't work in a number of scenarios. The focus of this How do I tackles how to approach this problem.

 

Interfaces and classes needed

 

Code snippet

Automation way

    DTE2 dte = serviceProvider.GetService(typeof(SDTE)) as DTE2;

 

    OutputWindowPane generalPane =

        dte.ToolWindows.OutputWindow.OutputWindowPanes.OfType<OutputWindowPane>()

            .FirstOrDefault(pane =>

                new Guid(pane.Guid).Equals(VSConstants.GUID_OutWindowGeneralPane));

 

    if(generalPane != null)

    {

        generalPane.OutputString("Test");

        generalPane.ForceItemsToTaskList();

    }

Assemblies needed

  • EnvDTE
  • EnvDTE80

Interop way

    IVsOutputWindow outputwindow = serviceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;

 

    Guid generalGuidPane = VSConstants.GUID_OutWindowGeneralPane;

    IVsOutputWindowPane generalPane;

 

    ErrorHandler.ThrowOnFailure(outputwindow.GetPane(ref generalGuidPane, out generalPane));

    generalPane.OutputStringThreadSafe("Test");

    ErrorHandler.ThrowOnFailure(generalPane.FlushToTaskList());

 

Assemblies needed

  • Microsoft.VisualStudio.Shell.Interop
  • Microsoft.VisualStudio.Shell.9.0

 

Stay tuned,

Pablo

posted Wednesday, August 20, 2008 6:48 AM by pga with 1 Comments