1

This question already has an answer here:

In my case, i have a model, that produce 2 Tables (zonal statistis). I have a script that should work with that tables. How do I pass these tables to a Script? my script takes certain fields in these 2 tables and store them in new table (+ some operations). Model looks like this:enter image description here

And the script looks like this:

import arcpy

result=arcpy.GetParameterAsText(0)

enviro=r"D:\Skola\Kart+geoinfo\Diplomka\Diplomka.gdb"
arcpy.env.workspace=enviro
new_T=arcpy.CreateTable_management(enviro,result)
arcpy.AddField_management(new_T,"ID","SHORT")
arcpy.AddField_management(new_T,"U_Vetrolamu","DOUBLE")
arcpy.AddField_management(new_T,"Od_Vetrolamu","DOUBLE")
arcpy.AddField_management(new_T,"rozdil","DOUBLE")
arcpy.AddField_management(new_T,"rozdil_procenta","DOUBLE")

with arcpy.da.SearchCursor(table,["MEAN","OBJECTID"]) as sCur:
 with arcpy.da.InsertCursor(new_T,["U_Vetrolamu","ID"]) as iCur:
      for row in sCur:
         iCur.insertRow(row)

data = {}
with arcpy.da.SearchCursor(table1, ["OBJECTID", "MEAN"]) as sc:
for row in sc:
    try:
     data[row[0]] = data[row[0]] + row[1]
    except KeyError:
        data[row[0]] = row[1]

with arcpy.da.UpdateCursor(result, ["ID", "Od_Vetrolamu"]) as uc:
     for row in uc:
        row[1] = data[row[0]]
        uc.updateRow(row)
arcpy.CalculateField_management(result, "rozdil", "[U_Vetrolamu] - [Od_Vetrolamu]", "VB", "")
arcpy.CalculateField_management(result, "rozdil", "([U_Vetrolamu] - [Od_Vetrolamu]/[U_Vetrolamu] - [Od_Vetrolamu])*100", "VB", "")

I need to use table and table1 from model in script...

marked as duplicate by Erica, Midavalo Apr 24 '17 at 17:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I think you need to look at SetParameterAsText. – PolyGeo Apr 24 '17 at 13:22