AnsweredAssumed Answered

Python toolbox (pyt): how to get output

Question asked by KevinBellSLC on Nov 25, 2014
Latest reply on Aug 6, 2020 by markjones_tps

It would be tremendously helpful if someone could post a sample python toolbox (pyt) that accepts a dummy input parameter or two, and returns "hello world of pyt gp services!"  I figure with that template, I could do my own gp routines during the execution, and replace the "hello world" with the results of my gp work.  I don't need any geometry returned, just text.


The use case here is to return nearby addresses from an input lat/long.


This code fails:


import arcpy

import os


class Toolbox(object):

    def __init__(self):

        self.label = "Get Nearby Addresses"

        self.alias = ""


        # List of tool classes associated with this toolbox = [GetNearbyAddresses]



class GetNearbyAddresses(object):

    def __init__(self):

        self.label = "Get Nearby Addresses"

        self.description = "Get Nearby Addresses within a buffer."

        self.canRunInBackground = False



    def getParameterInfo(self):


        params = []


        param0 = arcpy.Parameter(

            displayName = "Latitude",

            name = "lat",

            datatype = "Double",

            parameterType = "Required",

            direction = "Input")



        param1 = arcpy.Parameter(

                    displayName = "Longitude",

                    name = "lon",

                    datatype = "Double",

                    parameterType = "Required",

                    direction = "Input")



        param2 = arcpy.Parameter(

            displayName = "Buffer Distance",

            name = "distance",

            datatype = "Long",

            parameterType = "Required",

            direction = "Input")



        param3 = arcpy.Parameter(

                    displayName = "Address List",

                    name = "addresses",

                    datatype = "GPString",

                    parameterType = "Derived",

                    direction = "Output")


        return params



    def execute(self, parameters, messages):


            arcpy.env.workspace = r'E:\gis\default.gdb'

            arcpy.env.overwriteOutput = True


            lat = parameters[0].valueAsText

            lon = parameters[1].valueAsText

            distance = parameters[2].valueAsText


            #inpoint = arcpy.Point(X=lon, Y=lat)

            #ptGeometry = arcpy.PointGeometry(inpoint, arcpy.SpatialReference(4326))


            #arcpy.Buffer_analysis(ptGeometry, 'buffer', distance + ' FEET', \

            #                      "FULL", "ROUND", "NONE", "")

            #get intersecting addresses here


            parameters[3].value = 'a nice list of addresses!'  # I need this from a gp service!





        except Exception, ErrorDesc:

            sErr = "ERROR:\n" + str(ErrorDesc)