I have a Search Cursor that operates at the end of the model. It works as intended but does not add the layer it ends up creating to the Map. I've tried connecting it to the "Collect Values" tool with Paramaters and Display selected, and it still won't work.
Here's the script:
import os
import sys
import arcpy
Filter_Layer = arcpy.GetParameterAsText(0) # Feature Layer
Search_Layer = arcpy.GetParameterAsText(1) # Feature Layer
Workspace = arcpy.GetParameterAsText(2) # Workspace
FP1 = os.path.abspath(Workspace)
events = arcpy.da.SearchCursor(Filter_Layer, ['Event'])
unique_events = list(set([row[0] for row in events]))
sql = "Event IN(" + ','.join(map(str, unique_events)) + ")"
arcpy.management.SelectLayerByAttribute(Search_Layer, "NEW_SELECTION", sql, None)
arcpy.management.CopyFeatures(Search_Layer, fr"{FP1}\RTL_Filtered", '', None, None, None)
Solved! Go to Solution.
Try adding a derived output parameter to your tool, then using the "SetParameter" or "SetParameterAsText" function in your script to put the output features into that parameter. Tools don't output data unless they have an output parameter configured.
Also for the future, what you're writing is a script tool in a normal toolbox, a Python toolbox is a different beast entirely.
Try adding a derived output parameter to your tool, then using the "SetParameter" or "SetParameterAsText" function in your script to put the output features into that parameter. Tools don't output data unless they have an output parameter configured.
Also for the future, what you're writing is a script tool in a normal toolbox, a Python toolbox is a different beast entirely.
It worked thank you!
Added a new paramater (output) and then,
arcpy.SetParameterAsText(3, outputFile)
mport os
import sys
import arcpy
Filter_Layer = arcpy.GetParameterAsText(0) # Feature Layer
Search_Layer = arcpy.GetParameterAsText(1) # Feature Layer
Workspace = arcpy.GetParameterAsText(2) # Workspace
FP1 = os.path.abspath(Workspace)
outputFile = fr"{FP1}\RTL_Filtered"
events = arcpy.da.SearchCursor(Filter_Layer, ['Event'])
unique_events = list(set([row[0] for row in events]))
sql = "Event IN(" + ','.join(map(str, unique_events)) + ")"
arcpy.management.SelectLayerByAttribute(Search_Layer, "NEW_SELECTION", sql, None)
arcpy.management.CopyFeatures(Search_Layer, fr"{FP1}\RTL_Filtered", '', None, None, None)
arcpy.SetParameterAsText(3, outputFile)