6

Is it possible to call an ArcPy script from a Java/.Net addin in ArcGIS 10.0?

Sunil
  • 4,763
  • 7
  • 43
  • 87
ChrisInCambo
  • 2,442
  • 17
  • 17

2 Answers2

6

Yes there are several ways to do this. I would recommend building a script tool and packaging it with your add-in. I have a sample project that does this listed in this answer: How can I programmatically get the path of "Python.exe" used by ArcMap

See also:

blah238
  • 35,793
  • 7
  • 94
  • 195
2

I call python script from my .net addin. I do it in a very simple way. I call it as I run process from .net code. Have a look at my code snippet

void RunPython(string scriptPath, string arguments)
{
     Process myProcess = new Process();
     try
     {
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardOutput = true;
            myProcess.StartInfo.FileName = "python";
            myProcess.StartInfo.Arguments = scriptPath + " " + arguments;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start();
            string result = myProcess.StandardOutput.ReadToEnd();

            Console.WriteLine(result);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
 }
Emi
  • 2,405
  • 2
  • 22
  • 40