1

I am beginner at Python scripting and just started using it with ArcGIS Pro by executing commands in the Python window. However, I can only get one command to run at a time.

For example, if I enter the following lines of code in the Input Area of the python window and press "ENTER", the cursor moves to a new line in the input window instead of executing the commands.

arcpy.management.AddField("JanInt_200k_geo", "Uwt", "DOUBLE", 6, 10, None, None, "NULLABLE", "NON_REQUIRED", None)
arcpy.management.AddField("JanInt_200k_geo", "Vwt", "DOUBLE", 6, 10, None, None, "NULLABLE", "NON_REQUIRED", None)
arcpy.management.AddField("JanInt_200k_geo", "SO4", "DOUBLE", 15, 20, None, None, "NULLABLE", "NON_REQUIRED", None)

Is there a way to run multiple commands (i.e. a larger selection of my script) using this window?

2

You can paste your entire script into the python window and ArcGIS Pro will run the entire script.

Example: I have a streets layer and a rivers layer. I want to buffer the river and clip the streets by that buffer using the following code

result = arcpy.Buffer_analysis("rivers", "riverBuf", "50 METERS")
print(result)
arcpy.Clip_analysis("streets", result, "streets_50m_of_rivers")

enter image description here

When I paste the code into the python pane and press enter twice the code will run.

enter image description here

The reason you need to hit enter twice is because when you paste a block of code arcpy allows you to add more code below it before running. Once you hit enter again you're signalling that you are adding no more code, and you want arcpy to run it.

Alternatively you could attach your script to a script-tool and run your script from the geoprocessing pane. This will also run your entire script.

  • When I paste in several lines into the Input Area and then press "ENTER", my cursor just moves to the next line in the Input Area instead of executing the command. I will update my question with a visual. – ellejay Feb 21 '17 at 17:10
  • 1
    @ellejay press enter twice! When you paste a block of code, pressing enter makes ArcGIS Pro think there may be more code that you're going to type in, so press it again to signal that you have no more code – Midavalo Feb 21 '17 at 17:17
  • Ah, thank you!! Also, @Midavalo, could you elaborate on your comment below: "Alternatively you could attach your script to a script-tool and run your script from the geoprocessing pane. This will also run your entire script." Alternatively, I can open another question - I am finding very few truly introductory resources that explain how to do this. – ellejay Feb 21 '17 at 17:31
  • @ellejay It would probably require another question to ask about creating script-tools in ArcGIS Pro. There may already be questions here if you do a search, but to get you started try Create a script tool and Adding a script tool on the ArcGIS Pro help/documentation site. – Midavalo Feb 21 '17 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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