1

I am trying to return a feature class (my sample data is a polygon fc) from a Python toolbox and cannot find any information about what I have to set to get it to work. This runs successfully and gives me a record count of 917 but in ArcCatalog in the results window out: <empty> (and the icon looks like a table not a polygon feature class).

import arcpy



class Toolbox(object):
    def __init__(self):
        self.label='BasicOutput'
        self.alias='BasicOutput'
        self.description='BasicOutput'
        self.summary=self.description

        # List of tool classes associated with this toolbox
        self.tools=[BasicOutput]


class BasicOutput(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label='BasicOutput'
        self.description='BasicOutput'
        self.summary=self.description


    def getParameterInfo(self):
        ps=[
            arcpy.Parameter(
                displayName='out',
                name='out',
                datatype='GPFeatureRecordSetLayer',
                parameterType='Derived',
                direction='Output'),
            ]
        return ps


    def updateParameters(self,parameters): return
    def updateMessages(self,parameters): return


    def execute(self,parameters,messages):
        fs=arcpy.FeatureSet()
        fs.load(r'D:\customApps\PaddockGRASP\BasicOutput.gdb/Cadastre')
        arcpy.AddMessage('record count: %s'%arcpy.GetCount_management(fs))
        parameters[0].value=fs

I will then be publishing it as a GP service in ArcGis server, but can't even get it working in ArcCatalog! Using ArcGis 10.2.1.

2

TLDR: Change parameters[0].value=fs to arcpy.SetParameterAsText(0,fs)

EDIT: after some minor testing, looks like arcpy.SetParameter also works.

EDIT2: Oops, just noticed that I also changed the datatype to DEFeatureClass.

OK, after many hours of trying various things and trawling through forums about problems that weren't the same as mine or about getting features as input instead of output, I stumbled on the simple solution (yet completely unintuitive to me). Despite the name of the function SetParameterAsText, it actually sets the return value to my feature class - returns the path in ArcCatalog which I can copy features from and returns JSON when published as a GPService.

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.