5

enter image description here

I am learning the usage of SetProgressor. I used the sample code from ArcGIS guide to test, as shown below.

import os
import arcpy

# Allow overwriting of output
arcpy.env.overwriteOutput = True

# Set current workspace
arcpy.env.workspace = r'E:\OilWells Model 20161010\test3\EachRoute'

# Get a list of shapefiles in folder
fcs = arcpy.ListFeatureClasses()

# Find the total count of shapefiles in list
fc_count = len(fcs)

# Set the progressor
arcpy.SetProgressor("step", "Copying shapefiles to geodatabase...",
                    0, fc_count, 1)

# Create a file gdb to contain new feature classes
arcpy.CreateFileGDB_management(arcpy.env.workspace, "fgdb.gdb")

# For each shapefile, copy to a file geodatabase
for shp in fcs:
    # Trim the '.shp' extension
    fc = os.path.splitext(shp)[0]

    # Update the progressor label for current shapefile
    arcpy.SetProgressorLabel("Loading {0}...".format(shp))

    # Copy the data
    arcpy.CopyFeatures_management(shp, os.path.join("fgdb.gdb", fc))

    # Update the progressor position
    arcpy.SetProgressorPosition()

arcpy.ResetProgressor()

When I run the above code in the built-in python shell of ArcGIS, I didn't find the progress bar. Can anyone tell me where is the progress bar showing when run the code?

I am using ArcGIS 10.3.1 Advanced License.

0

1 Answer 1

9

When you run a script tool in ArcGIS the progress bar will show on the dialog that displays. It does not display when running from the ArcGIS Python window.

You can get more info on how it works and how to use it on the SetProgressor page on ArcGIS Desktop Help.

For example, using a script tool pointing at this basic script:

import arcpy, time
arcpy.SetProgressor("step", "working...", 0, 5, 1)

for i in range (0, 5, 1):
    arcpy.AddMessage("Step {}".format(i))
    arcpy.SetProgressorLabel("Step {}".format(i))
    arcpy.SetProgressorPosition(i)
    time.sleep(2)

I get a progress bar for each i step:

enter image description here

3
  • Do you mean the dialog under the python shell, which shows the elapsed time as the picture I just posted?
    – Tianxin Li
    Commented Oct 10, 2016 at 23:22
  • No. You need to add your script as a script tool into the ArcToolbox window and run your script from there. The dialog that appears to say your script is running will display the progess.
    – Midavalo
    Commented Oct 10, 2016 at 23:24
  • Got u. It makes sense to me now.
    – Tianxin Li
    Commented Oct 10, 2016 at 23:29

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.