Returning feature class from Python toolbox
We are searching data for your request:
Upon completion, a link will appear to access the found materials.
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: (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:customAppsPaddockGRASPBasicOutput.gdb/Cadastre') arcpy.AddMessage('record count: %s'%arcpy.GetCount_management(fs)) parameters.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.
EDIT: after some minor testing, looks like
EDIT2: Oops, just noticed that I also changed the datatype to
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.