Geoprocessing Blog

Showing results for 
Show  only  | Search instead for 
Did you mean: 

Other Boards in This Place

Latest Activity

(3 Posts)
Esri Contributor

This blog contains the scripts presented in the UC 2023 presentation, Getting Started with Python Automation. You are welcome to use these are learning tools.


1 0 913
MVP Regular Contributor

As per the Esri doc:

It is a common misconception that only tools downstream of a model iterator will run multiple times. When a model contains an iterator, all processes in the model will be run multiple times.

All tools that need to run multiple times should be placed in one model with a model iterator and used as a submodel. The tools that only need to be run once should be placed in the main model, which calls the iterating submodel.


The workaround is to use nested submodels:

0 0 207
by Anonymous User
Not applicable

I have had a desire to set a switch/flag in geoprocessing scripts that log at a level corresponding to the setting in the server.

The 'Message Level' setting can be accessed using the python api. 

I accomplished this via a small function as follows.

from arcgis.gis import GIS

def get_server_loglevel(checkservicename):
    infolevel = None """set infolevel to None and handle None separately 
                        or set infolevel to a default - e.g. 'info' """
    for folder in servicesdirectory.folders:
        folder_services = servicesdirectory.list(folder=folder)
            for folderservice in folder_services:
                service = folderservice.service
                servicename =
                if servicename == checkservicename:
                    # match the service name from the script to the one in the server
                    if 'showMessages' in
                        infolevel =

    return infolevel
# obtain the gis (portal) object 
gis = GIS(r'', 'portaladmin', 'Passw0rd', verify_cert=False)

# call the federated hosting server
federatedserver = gis.admin.servers.get(role="HOSTING_SERVER")[0]

# get the servicesdirectory object.
servicesdirectory = federatedserver.content

serverloglevel = get_server_loglevel(servicename, servicesdirectory)

# use serverloglevel in the script to log accordingly.‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The use for this may be a bit unconventional but it has helped to pass control of the 'log level' to the geoprocessing script so log files can also be written based on the server log level.

import logging

general_loglevels = {'Error':'ERROR', 'Warning': 'WARNING', 'Info': 'INFO'}


if serverloglevel in general_loglevels:
    loglevel = general_loglevels[serverloglevel]
    loglevel = 'DEBUG'

logger = logging.getLogger("GP Service")
level = logging.getLevelName(loglevel)

6 1 1,352
115 Subscribers