15

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 11, 2012 at 19:52

2 Answers 2

25

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.

answered Jan 11, 2012 at 20:03
0
0

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.

answered May 11, 2014 at 1:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.