[Ironpython-users] Automating Visual Studio with IronPython

Denis denis at camfex.cz
Sun Jun 26 13:23:08 CEST 2011


Hi
I am trying to automating some boring task by writing macros for
Visual Studio 2010.
I am not a .NET nor C# expert, I work with C++ and have some Python background.
So Python seemed more comfortable for me to do the task.

What I got stuck on is receiving Visual Studio events.
Some of them can be handled well but other are not.
By irony, the latters events are the ones that needed to be handled.

Ok, let us start from IronPython console in Visual Studio 2010.


>> import clr
>> clr.AddReference("EnvDTE")
>> import EnvDTE, System.Runtime.InteropServices.Marshal
>> dte = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE")

>> def onopen(): print 'solution opened!'
>> EnvDTE._dispSolutionEvents_Event.add_Opened(dte.Events.SolutionEvents, onopen)


Ok, the event installed and even works fine.
Lets go on.


>> def onupdated(): print 'pane updated!'
>> EnvDTE._dispOutputWindowEvents_Event.add_PaneUpdated(dte.Events.OutputWindowEvents, onupdated)
Traceback (most recent call last):
 File "<string>", line 1, in <module>
TypeError: expected _dispOutputWindowEvents_Event, got DispCallable

>» print type(dte.Events.OutputWindowEvents)
<type 'DispCallable'>

>» print type(dte.Events.SolutionEvents)
<type '__ComObject'>


Oops.
Seems like dte.Events.SolutionEvents and dte.Events.OutputWindowEvents
are not similar at all.
Why do they have so different type?
Both events works similar way with VisualBasic.

Thinking that DispCallable may have something todo with IDispatch,
lets try another way:


> dte.Events.OutputWindowEvents("add_PaneUpdated", onupdated)
Traceback (most recent call last):
 File "<string>", line 1, in <module>
StandardError: Error while invoking OutputWindowEvents.


Oops again :(
So how to deal with DispCallable?
How to query interface _dispOutputWindowEvents_Event on it?

Thanks in advance.


More information about the Ironpython-users mailing list