Using Model Builder, how to define directory while using a Python script?

1989
10
Jump to solution
08-13-2014 12:08 PM
LanceWilson
New Contributor III

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. I appreciate any help and suggestions, thank you!

oNhpE.jpg

My model runs as follows:

1. It establishes a connection to an Oracle dB

2. It creates a Query Layer based on the pre-filled 'Query' parameter
3. It creates an empty feature class (Empty FC) into a pre-filled GdB parameter
4. It then exectures the 'Copy Features' tool on the Query Layer and outputs the copy into the Empty FC
5. This newly populated feature class is then given a new field, called 'SUM_Quantity_Solid'

6. 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 'id' values
    Slist = list() for row in arcpy.da.SearchCursor(fc, 'id'):
     # if the value isn't in the list then add it to the list
     if not row[0] in Slist:
         Slist.append(row[0])
 
 for Value in Slist:
     # definition query to limit the rows in the cursor
    DefQ = 'id = ' + str(Value)
 
     # Use a generator expression to populate a list from the 'QUANTITY_SOLID' field
     b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID',DefQ))
 
     with arcpy.da.UpdateCursor(fc, ['SUM_Quantity_Solid'],DefQ) as cursor:
         for row in cursor:
             row[0] = 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.

0 Kudos
10 Replies
LanceWilson
New Contributor III

Great, thank you so much for your help Curtis!

0 Kudos