AW: [help] Driving Visual Studio From Python

Stefan Schukat SSchukat at dspace.de
Tue Nov 27 02:40:46 EST 2001


Hi,

you are using dynamic invocation through "win32com.client.Dispatch"
therefore
your makepy generated wrapper is possibly of no help. Try to import the 
generated wrapper or use win32com.client.gencache.EnsureDispatch.

Otherwise the code you are looking for is:
import win32com.client
app = win32com.client.gencache.EnsureDispatch( 'MSDev.Application')
app.AddProject("MyProj", "c:\myproj", "Console Application", 1)

Bur unfortunaly there is no code to read the project properties.
You could only add or remove settings in the following way
(For the first configuration in the first project)

if app.Projects[1].Type == "Build":
   app.Projects[1].Configurations[1].AddFileSettings("myfile.cpp",
"/D_DEFINEME")

or:
app.ActiveProject.Configurations[1].AddFileSettings("myfile.cpp",
"/D_DEFINEME")
app.ActiveConfiguration.AddFileSettings("myfile.cpp", "/D_DEFINEME")

if a configuration object is available

Conf.RemoveToolSettings("cl.exe", "/GX")
Conf.AddToolSettings("cl.exe", "/D_DEFINEME")
Conf.RemoveFileSettings("stdafx.cpp", "/WX")


Bye

		Stefan

> 
> 
> Hello  All,
> 
> I am an old unix developer finally moving to Windows Visual 
> C++.  I have
> been using python on Unix since 96,
> and have been really happy with python as a scripting/tools language.
> 
> I need to drive visual studio to create projects, add configurations,
> and add files to projects.
> 
> The COM extensions  make it look like it is possible to do this, but I
> am having trouble getting
> it going.
> 
> I have ran makepy and added the visual studio type libs.
> 
> I copied the following code from a post
> 
> -----------------------------------------
> import win32com.client
> app = win32com.client.Dispatch( 'MSDev.Application')
> 
> wnd = app.ActiveWindow
> if wnd.Type == 'Text':
>     print wnd.Selection
> app = None
> ------------------------------------------
> 
> This prints on the selected test.
> 
> I can't seem to get the syntax to obtain and print out project
> properties, or to add a project
> 
> 
> Could someone help my out by giving me the python code to try to get
> this to go, I am missing something
> very basic here.
> 
> Thanks
> Mike
> 
> PS.  I added the MSDEV links to the visual studio docs
> ++++++++++++++++++
> DeveStudio Link to add project
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vcug98/html/vcrefaddprojectmethod.asp

Link to Visual Studio Application Object

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcug98/html
/_asug_application_object.asp




More information about the Python-list mailing list