Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Are there any available examples that show how python can be integrated into a .NET ArcGIS Addin or Extension? I have a series of python scripts that I would like to call from form events (e.g. button clicks) in .NET. I would also like to be able to set variables in the script from a .NET form.

Should I bite the bullet and re-write these scripts in .NET, or is there a simple way to wrap the python code?

share|improve this question

2 Answers 2

up vote 22 down vote accepted

Keep in mind that Arcpy is essentially a wrapper around ArcObjects. But if you're just trying to call some Python scripts that you don't want to have to rewrite you can spawn a process that calls the python executable with your args.

var startInfo = new ProcessStartInfo() {
   CreateNoWindow = false,
   UseShellExecute = false,
   FileName = pathToPythonRuntime,
   WindowStyle = ProcessWindowStyle.Hidden,
   Arguments = pathToYourPythonScriptYouDoNotWantToRewrite+" "+yourOtherArgsEtc
 };
var exeProcess= Process.Start(startInfo);
//If you need synchronous execution you can do this
exeProcess.WaitForExit();

Note that you can do some pretty cool multithreading stuff with this too.

share|improve this answer
    
Perfect - thanks for the quick response. –  Nick Ochoski Jan 12 '12 at 18:53

From your Question I am not sure how wedded to .NET you are but, if you are using ArcGIS 10.1 (or later) for Desktop, then I think a simpler approach will be to use a Python AddIn:

ArcGIS 10.1 introduces Python to the list of languages for authoring Desktop add-ins, providing you with an easy solution to extend desktop functionality. To simplify the development of Python add-ins, you must download and use the Python Add-In Wizard to declare the type of customization. The wizard will generate all the required files necessary for the add-in to work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.