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
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
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