code_junkie

How to script Visual Studio 2008 from Python?

Nov 11th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import win32com.client
  2. app1 = win32com.client.Dispatch( 'Excel.Application' ) # ok
  3. app2 = win32com.client.Dispatch( 'Word.Application' ) # ok
  4. app3 = win32com.client.Dispatch( 'MSDev.Application' ) # error
  5.  
  6. >>> import win32com.client
  7. >>> b = win32com.client.Dispatch('VisualStudio.DTE')
  8. >>> b
  9. <COMObject VisualStudio.DTE>
  10. >>> b.name
  11. u'Microsoft Visual Studio'
  12. >>> b.Version
  13. u'8.0'
  14.  
  15. import win32com.client
  16. oAutoItX = win32com.client.Dispatch( "AutoItX3.Control" )
  17.  
  18. oAutoItX.Opt("WinTitleMatchMode", 2) #Match text anywhere in a window title
  19.  
  20. width = oAutoItX.WinGetClientSizeWidth("Firefox")
  21. height = oAutoItX.WinGetClientSizeHeight("Firefox")
  22.  
  23. print width, height
  24.  
  25. import comtypes.client as client
  26.  
  27. vs = client.CreateObject('VisualStudio.DTE')
  28.  
  29. commands = [command for command in vs.Commands if bool(command.Name) or bool(command.Bindings)]
  30. commands.sort(key=lambda cmd : cmd.Name)
  31.  
  32. f= open('bindings.csv','w')
  33.  
  34. for command in commands:
  35. f.write(command.Name+"," +";".join(command.Bindings)+ "n")
  36.  
  37. f.close()
Add Comment
Please, Sign In to add comment