I'm having trouble setting a "Feature Set" output parameter from a .pyt .. I'm using ArcGIS 10.1 SP1.
Here’s a short script that can be invoked either from a classic toolbox (thru the main() function; one setup with same parameters here), or as a .pyt .. it works as expected when invoked from a classic toolbox, but does not as a .pyt:
import arcpy
class Toolbox(object):
def __init__(self):
self.label = “FeatureSet Output Test”
self.alias = “”
self.tools = [Test]
class Test(object):
def __init__(self):
self.label = “Test1”
self.description = “Output a few points in a feature set”
self.canRunInBackground = False
def getParameterInfo(self):
params = []
param0 = arcpy.Parameter(
displayName = “FS Output”, name = “fsOutput”,
datatype = “Feature Set”, parameterType = “Derived”, direction = “Output”)
params.append(param0)
param1 = arcpy.Parameter(
displayName = “JSON Output”, name = “strOutput”,
datatype = “String”, parameterType = “Derived”, direction = “Output”)
params.append(param1)
return params
def execute(self, parameters, messages):
gdbPath = ‘in_memory’
featureClassName = ‘points’
featureClass = ‘{}/{}’.format(gdbPath, featureClassName)
try:
arcpy.AddMessage(‘Creating a point feature class with 1 text attribute’)
if arcpy.Exists(featureClass):
arcpy.Delete_management(featureClass)
arcpy.CreateFeatureclass_management(
out_path=gdbPath, out_name=featureClassName, geometry_type=’POINT’,
spatial_reference=arcpy.SpatialReference(4326))
arcpy.AddField_management(
in_table=featureClass,
field_name=’Attribute1’, field_type=’TEXT’)
arcpy.AddMessage(‘Inserting a couple points’)
with arcpy.da.InsertCursor(featureClass, (‘SHAPE@XY’, ‘Attribute1’)) as cur:
cur.insertRow(((1, 1), ‘point at 1, 1’))
cur.insertRow(((2, 2), ‘point at 2, 2’))
arcpy.AddMessage(‘Setting the output parameters’)
featureSet = arcpy.FeatureSet(featureClass)
# Has no effect in either .tbx or .pyt case .. no error, just does nothing.
parameters[0].value = featureSet
# Does what's expected for classic .tbx; does nothing
# for .pyt .. again, no error, just does nothing.
# You can comment this line out for testing the first set method ..
arcpy.SetParameter(0, featureSet)
# This works fine in both .tbx and .pyt
parameters[1].value = featureSet.JSON
except Exception as e:
arcpy.AddError(str(e))
def main():
tool = Test()
tool.execute(arcpy.GetParameterInfo(), None)
if __name__ == ‘__main__’:
main()
Not sure what I'm doing wrong .. Any suggestions?