Skip to main content
added 1 characters in body
Source Link
Random Geo guy
  • 2k
  • 3
  • 21
  • 31

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.

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.

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.

Source Link
Random Geo guy
  • 2k
  • 3
  • 21
  • 31

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.