Geoprocessing Blog

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

Other Boards in This Place

Latest Activity

(3 Posts)
TimothyKinlaw
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.

Read more...

more
1 0 973
AndresCastillo
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.

https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/modelbuilder/add-a-submodel-to-...

 

The workaround is to use nested submodels:
https://www.youtube.com/watch?v=yqYgs61w2YI

more
0 0 247
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 = service.properties.serviceName
                
                if servicename == checkservicename:
                    # match the service name from the script to the one in the server
                    if 'showMessages' in service.properties.properties:
                        infolevel = service.properties.properties.showMessages

    return infolevel
 
# obtain the gis (portal) object 
gis = GIS(r'https://fully.qualified.domain.name/portal', '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'}

# https://docs.python.org/3/library/logging.html#logging-levels


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

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

more
6 1 1,423
118 Subscribers