I have a model (shown below) in which at the very end of it I run a Python script ('SumFieldInsertNew'). One issue I'm having is that I'm creating this model for an end-user that will have little to no knowledge of most things computer-wise. Ergo, I'm trying to make it as hassle-free and flexible as possible. My question is, I want the user to be able to name the file the script will run itself on, but am unsure of how to do something like this. So essentially, I want to make 'Empty FC' a parameter in which the user can decide what they want their file to be named. Then have the Python script directory code (where it's defining the feature class), know that whatever the user named it is conditional to it being able to run its processes.
My model runs as follows:
It establishes a connection to an Oracle dB
It creates a Query Layer based on the pre-filled 'Query' parameter
- It creates an empty feature class (Empty FC) into a pre-filled GdB parameter
- It then exectures the 'Copy Features' tool on the Query Layer and outputs the copy into the Empty FC
This newly populated feature class is then given a new field, called 'SUM_Quantity_Solid'
In which lastly, this new field is populated via the Python script 'SUM_FIELD_INSERT_NEW', which (as seen below), SUMs up a field and then inserts the values.
> import arcpy > > # Define the feature class fc = r'User_Defined_Path' > > # find the unique 'SEGMENT_LENGTH' values Slist = list() for row in arcpy.da.SearchCursor(fc, 'SEGMENT_LENGTH'): > # if the value isn't in the list then add it to the list > if not row in Slist: > Slist.append(row) > > for Value in Slist: > # definition query to limit the rows in the cursor > DefQ = 'SEGMENT_LENGTH = ' + str(Value) > > # Use a generator expression to populate a list from the 'QUANTITY_SOLID' field > b = sum(row for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID'),DefQ) > > with arcpy.da.UpdateCursor(fc, ['QUANTITY_SOLID_SUM'],DefQ) as cursor: > for row in cursor: > row = b > cursor.updateRow(row)
As referenced, I would like to be able to have
fc = r'User_Defined_Path'
be what the user initially defined the 'EMPTY FC' filename parameter as.