3

I am using ArcGIS 10.2.

Using QGIS, I have a text editor that allows me to write some lines of code and quickly test them:

enter image description here

Is there something similar using ArcGIS?

I know I can simply write this line in the built-in Python Console (like suggested here):

execfile('path_to_my_python_script')

but is there a direct way for doing it within ArcGIS or, in other words, without writing every time the filepath for calling an external file?

1 Answer 1

4

The Answer you link to in your Question lets you trigger external Python scripts. But, the ArcMap Python Window still lets you run snippets even if you don't have an existing external script yet.

The Python window can be opened within any ArcGIS for Desktop application by clicking the Python window button Python icon on the Standard toolbar.

This is handy for quickly testing ideas and running very short scripts, but also for interacting with layers within ArcMap.

example Python snippet, from Esri help site

The closest to what you want is the IDLE code editor which is packaged with an ArcGIS install, or any IDE of your choice. This saves files to disk before running them, but you just have to hit F5 to kick it off rather than typing execfile or similar. However, it won't interact with a layer in an MXD, and so there are some limitations over what had available in QGIS. I can see how that would be a big step down -- I also find the copy-and-paste editing process to be tedious and frustrating when I'm working within the Python window! (Almost all my scripts are now put together in IDLE.)

5
  • +1 thanks for your answer, but I'm already using it and it is not very comfortable coming from QGIS. Actually, I'm wondering if there is a way for having a text editor that is run as a whole every time (the ArcMap Python Window, instead, runs the code line by line, i.e. I need to copy-and-paste it every time if I want to modify something inside it): in other words, if there is a way for having a Run button as in QGIS.
    – mgri
    Sep 24, 2017 at 20:02
  • @mgri Shift+ Enter should allow adding additional lines before running all code. Or you can copy/paste text blocks in
    – Midavalo
    Sep 24, 2017 at 21:19
  • @Midavalo thanks, I know this option and I will probably give up on this and use an external text editor + the execfile command for my purposes.
    – mgri
    Sep 24, 2017 at 21:24
  • The closest to what you want is the IDLE code editor which is packaged with an ArcGIS install; it does save files to disk before running them, but you just have to hit F5 to kick it off rather than typing execfile or similar. However, it won't interact with a layer in an MXD, and so has some limitations over what you seem to have had available in QGIS. I can see how that would be a big step down, I also find the copy-and-paste to be tedious and frustrating when I'm working within the Python window. (Almost all my scripts are now put together in IDLE.)
    – Erica
    Sep 24, 2017 at 21:44
  • 1
    @Erica I think I will continue to use the IDLE code editor that is packaged with ArcGIS. However, it seems that there isn't a way for having the same QGIS functionality here. Your last comment should be added to the answer for the sake of clearness. Thanks for the effort.
    – mgri
    Sep 24, 2017 at 21:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.