I have a working model that filters data down to a few layer files. I also have a working python script that will take those filtered layers and further filter them. As of now I have to run the model and then run the script, I'm trying to merge the processes for efficiency. When I drag the script into Modelbuilder or try to create another model to do a model within a model, the process will run except the searchcursor won't do any "searching."
Heres the Script
import os
import sys
import arcpy
Workspace = arcpy.GetParameterAsText(0) # Workspace
Points_Filtered = arcpy.GetParameterAsText(1) # Feature Layer
Event_id = arcpy.GetParameterAsText(2) # Event_ID
RTL_Unfiltered = arcpy.GetParameterAsText(3) # Feature Layer
FP1 = os.path.abspath(Workspace)
outputFile = fr"{FP1}\RTL_Filtered"
events = arcpy.da.SearchCursor(Points_Filtered, Event_id)
unique_events = list(set([row[0] for row in events]))
sql = "event_id IN(" + ','.join(map(str, unique_events)) + ")"
arcpy.management.SelectLayerByAttribute(RTL_Unfiltered, "NEW_SELECTION", sql, None)
arcpy.management.CopyFeatures(RTL_Unfiltered, outputFile, '', None, None, None)
arcpy.SetParameterAsText(4, outputFile)
Are you saying in the image you have uploaded that "SearchCursor" is a model? Also the inputs to "SearchCursor" are all grey, they have not been set, so not surprising that "SearchCursor" is not running.
There is little point setting them as Parameters if you intend to run the model within modelbuilder.
Its just a picture to show that portion of the process since my model is a little more complex. The model stays gray since it requires user input when ran even when all the parameter's are defined/connected.
The process runs just the searchcursor portion of the script doesn't work when inserted into the model.
OK, without seeing what "SearchCursor" is no one can answer this question. I suspect the inputs are the wrong data type that they are feeding into. Share that portion of the model with some sample data?
import os
import sys
import arcpy
Workspace = arcpy.GetParameterAsText(0) # Workspace
Points_Filtered = arcpy.GetParameterAsText(1) # Feature Layer
Event_id = arcpy.GetParameterAsText(2) # Event_ID
RTL_Unfiltered = arcpy.GetParameterAsText(3) # Feature Layer
FP1 = os.path.abspath(Workspace)
outputFile = fr"{FP1}\RTL_Filtered"
events = arcpy.da.SearchCursor(Points_Filtered, Event_id)
unique_events = list(set([row[0] for row in events]))
sql = "event_id IN(" + ','.join(map(str, unique_events)) + ")"
arcpy.management.SelectLayerByAttribute(RTL_Unfiltered, "NEW_SELECTION", sql, None)
arcpy.management.CopyFeatures(RTL_Unfiltered, outputFile, '', None, None, None)
arcpy.SetParameterAsText(4, outputFile)
You Script tool (so not model) code takes 4 parameters, in your image you are not connecting in Event_id, the 3rd of 4.
Event_id = arcpy.GetParameterAsText(2) # Event_ID
Which suggests your current parameters are potentially linking to the wrong input parameter as well as not providing all four required parameters?
You have set the parameters to the model variables but you have not set the model variables, I know this as they are grey. Right click on them, open them in your model and set them to the actual dataset.
Also looking at your code you have hard wired the SQL where clause to event_id, so why offer it up as a parameter?
Are you actually entering the the field name for Event_id on line 6? That is what you are telling the search cursor on line 10.
First input is dataset, second is field list.
R_