7

In ArcMap 9.x how can I attach a python script to a button?

asked Jul 27, 2010 at 23:19
3
  • What do you mean by a button? The easiest way to integrate a python script into ArcMap is through Toolbox. Is that okay? Commented Jul 28, 2010 at 0:10
  • no, not through a toolbox. that takes up too much screen real estate. Commented Jul 28, 2010 at 14:18
  • arcmap 10 version of this question: gis.stackexchange.com/questions/1697/… Commented Oct 4, 2011 at 22:26

3 Answers 3

7

This works in VBA to run a Python script. Just call the subroutine with a button.

Private Sub python_Click()
 Shell "C:\Python25\python.exe ""C:\rowcount.py"
End Sub

Hope this helps.

answered Jul 28, 2010 at 17:27
2
  • 2
    this is a good example of why this stack exchange platform works. I had an answer ready, but this one is simpler and cleaner. Thanks :) Commented Jul 28, 2010 at 18:16
  • What about .net? Any code snippets? Commented Jul 28, 2010 at 19:04
5

As @fmark says, the easiest way to integrate a Python script into ArcMap is through a toolbox, which I'd recommend.

That said, if you really need to (eg, you need a nicer front end than the toolbox) you have two options:

  1. You can call the script as a command line argument from another program that is linked to the button - the easiest would be VBA.
  2. You can add the Python script to the toolbox, and call the custom toolbox from your button (VBA, VB.Net, C#.Net).

Still, I'd go with @fmark and just add the script to the toolbox given the choice.

answered Jul 28, 2010 at 5:55
2

The way to do it in C# would be like this using the ArcGIS template for a button.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace RunEditPython
 { 
 public class PythonEdited : ESRI.ArcGIS.Desktop.AddIns.Button
 {
 public PythonEdited()
 {
 }
 protected override void OnClick()
 {
 System.Diagnostics.Process.Start("C:\\temp\\WHP\\WellsEdited.py");
 }
 protected override void OnUpdate()
 {
 Enabled = ArcMap.Application != null;
 }
}

}

answered Apr 12, 2011 at 14:36
1
  • thanks! and welcome to GIS stack exchange. I hope you find your time here fruitful; you've certainly come bearing gifts, it's appreciated. Commented Apr 12, 2011 at 17:37

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.