0

I am trying to port an arcpy python toolbox from ArcMap to ArcGIS Pro. In ArcMap I had to use the 64-Bit-geoprocessing tool because of the size of the datasets, so I wrote a wrapper-Script for the tool. That worked totally fine in Python27.

The wrapper-script lookes like this:

import arcpy
import traceback
import sys

"""
For 64-bit-processing:

execfile(r'D:\datensync\Fleischer_Box\BORIS.NRW-Verarbeitung\ils_brw_gewichtet_64bit_starter.py')
exec(open(r'D:\datensync\Fleischer_Box\BORIS.NRW-Verarbeitung\ils_brw_gewichtet_64bit_starter.py').read()) # python3
"""

arcpy.ImportToolbox(r'D:\datensync\Fleischer_Box\BORIS.NRW-Verarbeitung\ils_brw_gewichtet.pyt')
arcpy.env.overwriteOutput = True

try:
    arcpy.boris_ilsbrwtool(
        grid=r'D:\datensync\Fleischer_Box\BORIS.NRW-Verarbeitung\BORIS_NRW_Verarbeitung.gdb\_200kmgrid_CLIP_EnvelopeSpannfelderPlus25',
        layeryears=[
            [r'D:\datensync\Fleischer_Box\BORIS.NRW-Verarbeitung\BRW2011_EPSG25832_Shape\BRW_2011_Polygon.shp','2011']
        ], 
        id="id", 
        klassifikation="FARBE", 
        brw="BRW",
        in_workspace=r"D:\datensync\Fleischer_Box\BORIS.NRW-Verarbeitung\BORIS_NRW_Verarbeitung_Final.gdb",
        devmode=True
    )
    print(arcpy.GetMessages())
except Exception as e:
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    print(arcpy.GetMessages())
    print(tbinfo)
    raise e

When I run it from a python3-shell I get this Traceback:

Traceback (most recent call last):
  File "D:\datensync\Fleischer_Box\BORIS.NRW-Verarbeitung\ils_brw_gewichtet_64bit_starter.py", line 37, in <module>
raise e
  File "D:\datensync\Fleischer_Box\BORIS.NRW-Verarbeitung\ils_brw_gewichtet_64bit_starter.py", line 29, in <module>
devmode=True
TypeError: boris() got an unexpected keyword argument 'grid'

I am guessing there are plenty of errors related to python3 in the actual toolbox, but even when I link an empty toolbox with the same parameters I get the same traceback. So I am guessing, with ArcGIS Pro and/or Python3, something has changed how parameters ar handled from shell.

Can anyone point me in the right direction on how to access an arcpy python toolbox from python3-shell?

Those are my parameter definitions:

def getParameterInfo(self):
    """Define parameter definitions"""
    params = []

    """
    params[0]
    """
    params.append(
        arcpy.Parameter(
            displayName="Grid LAEA Bundesamt fuer Kartographie und Geodaesie.",
            name="grid",
            datatype='Feature Layer',
            parameterType="Required",
            direction="Input"
        )
    )

    """
    params[1]
    """
    params.append(
        arcpy.Parameter(
            displayName="Feature-Classes containing the Bodenrichtwertzonen.",
            name="layeryears",
            datatype='GPValueTable',
            parameterType="Required",
            direction="Input"
        )
    )
    params[1].columns = [ ['DEFeatureClass', 'FeatureClass'], ['GPString', 'Jahr'] ]

    """
    params[2]
    """
    params.append(
        arcpy.Parameter(
            displayName="id-Feld des Grids - Defaults to id - DARF NICHT DIE OID SEIN (ggf. kopieren...)!",
            name="id",
            datatype='GPString',
            parameterType="Required",
            direction="Input"
        )
    )
    params[2].value='id'
    """
    params[3]
    """
    params.append(
        arcpy.Parameter(
            displayName="Farbe-Feld/Klassifikation (same on all BRW Feature CLasses!) - defaults to FARBE",
            name="klassifikation",
            datatype='GPString',
            parameterType="Required",
            direction="Input"
        )
    )    
    """
    params[4]
    """
    params.append(
        arcpy.Parameter(
            displayName="Bodenrichtwert-Feld (same on all BRW Feature CLasses!) - defaults to BRW",
            name="brw",
            datatype='GPString',
            parameterType="Required",
            direction="Input"
        )
    )   
    """
    params[5]
    """
    params.append(
        arcpy.Parameter(
            displayName="Workspace (defaults to grid-workspace; only database, no shapefile)",
            name="in_workspace",
            datatype="DEWorkspace",
            parameterType="Required",
            direction="Input"
        )
    )
    params[5].value = os.path.abspath(arcpy.env.workspace)
    params[5].filter.list=['Local Database','Remote Database']
    """
    params[6]
    """
    params.append(
        arcpy.Parameter(
            displayName="Erweiterte Ausgabe aktivieren (\"verbose\" bzw. \"devmode\")",
            name="devmode",
            datatype="GPBoolean",
            parameterType="Required",
            direction="Input"
        )
    )
    params[6].value = True

    return params

And this is how the tool is initiated:

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "ILS Bodenrichtwert Tool"
        self.alias = "ilsbrwtool"
        # List of tool classes associated with this toolbox
        self.tools = [boris]


class boris(object):

    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        (snip)
  • Without debugging anything, and as a guess: try removing the name arguments from the tool call >> arcpy.boris_ilsbrwtool(. So instead of grid=r'D:\datensync\Fleis... just go r'D:\datensync\Fleis... – KHibma Mar 18 at 14:24
  • Well, I tried that, though then I got something like "boris() only allows 0 attributes but got 7"... – Janne Jakob Fleischer Mar 18 at 18:05
  • 1
    Sounds like a problem with the PYT itself then? Can you execute it from within ArcGIS Pro as a tool? – KHibma Mar 18 at 18:38
  • Not yet. Because I have several wrapper Scripts around toolboxes, I would like to understand this issue first. In general: Should my code above work? – Janne Jakob Fleischer Mar 19 at 9:32
0

Well, the problem is not with the above code, but with the error reporting of esri.

The problem wasn't with the code above or the wrong parameters as the traceback mentioned, but with .pyt or the runtime environment in general: One of the librarys I import into the toolbox couldn't be loaded. It was just a broken conda environment.

I found out by running the code from the .pyt-file line by line in a python console.

Actually the wrapper class and the .pyt is working quite fine now with ArcGIS-Pro-Arcpy in Python 3 console, though it can't be loaded into ArcGIS Pro Toolbox for whatever (silent) reason, but that is another issue.

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.