Creating button in ArcMap to run Python program?

If you don't need any input or outputparameters, this sample should be possible to use to run a script in a custom command Leveraging ArcPy in a .NET application, C# example:

// Executes a shell command synchronously.
// Example of command parameter value is
// "python " + @"C:\scripts\geom_input.py".
//
public static void ExecuteCommand(object command)
{
    try
    {
        // Create the ProcessStartInfo using "cmd" as the program to be run,
        // and "/c " as the parameters.
        // "/c" tells cmd that you want it to execute the command that follows,
        // then exit.
        System.Diagnostics.ProcessStartInfo procStartInfo = new
            System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);

        // The following commands are needed to redirect the standard output.
        // This means that it will be redirected to the Process.StandardOutput StreamReader.
        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.UseShellExecute = false;

        // Do not create the black window.
        procStartInfo.CreateNoWindow = true;

        // Now you create a process, assign its ProcessStartInfo, and start it.
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo = procStartInfo;
        proc.Start();

        // Get the output into a string.
        string result = proc.StandardOutput.ReadToEnd();

        // Display the command output.
        Console.WriteLine(result);
    }
    catch (Exception objException)
    {
        Console.WriteLine(objException.Message);
        // Log the exception and errors.
    }
}

Use [Add Tools...] in Toolbar / Customize to add the script to a category. Then pull the script to the toolbar of choice.


Right click a blank area next to your toolbars > open the customize window > click on the commands tab > scroll to the bottom of the list and click [UI Control] > Select new UI Control > select the type of control that you want and then click Create and Edit. This will open the VBA editor for the new control and you can write your code inside hear and define the event that calls the code. VBA is included with 10 for free but you will need to request a license file for it and then register that license. Call ESRI for this and they should give you a license free of charge. After 10 this will go away...