In ArcMap 10.4.1 I made several models with the ModelBuilder and then I exported them to a Python script. I want to keep/define all parameters and settings of the tools centrally in a table and let the python script read it from there.
Is it possible to do this with Python and how do I read parameters from an external table instead of hard-coding them?
Below the code:
I want to get the distance from buffer tool out of a table from a database (now hard-coded 8 meters) and the dissolve fields as well and don't want manual interference.
# Import arcpy module
import arcpy
# Script arguments
PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved__4_ = arcpy.GetParameterAsText(0)
if PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved__4_ == '#' or not PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved__4_:
PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved__4_ = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved" # provide a default value if unspecified
PS_P_Brugge_Enriched = arcpy.GetParameterAsText(1)
if PS_P_Brugge_Enriched == '#' or not PS_P_Brugge_Enriched:
PS_P_Brugge_Enriched = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched" # provide a default value if unspecified
# Local variables:
PS_P_Brugge_Enriched_Buffer__2_ = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_Buffer"
PS_P_Brugge_Enriched_Dissolve = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_Dissolve"
PS_P_Brugge_Enriched_DissolvedBuffer_temp = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_DissolvedBuffer_temp"
PS_P_Brugge_Enriched_DissolvedBuffer_temp2 = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_DissolvedBuffer_temp2"
PS_P_Brugge_Enriched_DissolvedBuffer__2_ = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_DissolvedBuffer"
PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved"
PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved__3_ = PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved
PS_P_Brugge_Enriched_DissolvedBufferTemp = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_DissolvedBufferTemp"
PS_P_Brugge_Enriched_DissolvedBuffer__4_ = PS_P_Brugge_Enriched_DissolvedBufferTemp
PS_P_Brugge_Enriched_DissolvedBufferTemp__2_ = PS_P_Brugge_Enriched_DissolvedBuffer__4_
PS_P_Brugge_Enriched_DissolvedBuffer = "C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Output\\Clustering\\PS_P_Brugge_Enriched_DissolvedBuffer"
# Process: Buffer (2)
arcpy.Buffer_analysis(PS_P_Brugge_Enriched, PS_P_Brugge_Enriched_Buffer__2_, "8 Meters", "FULL", "ROUND", "NONE", "", "PLANAR")
# Process: Dissolve (3)
arcpy.Dissolve_management(PS_P_Brugge_Enriched_Buffer__2_, PS_P_Brugge_Enriched_Dissolve, "Status;Material;OperatingPressure", "", "SINGLE_PART", "DISSOLVE_LINES")
# Process: Spatial Join (2)
arcpy.SpatialJoin_analysis(PS_P_Brugge_Enriched, PS_P_Brugge_Enriched_Dissolve, PS_P_Brugge_Enriched_DissolvedBuffer_temp, "JOIN_ONE_TO_MANY", "KEEP_ALL", "Shape_Length \"Shape_Length\" false true true 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,Shape_Length,-1,-1;PipeSegment_GlobalID \"PipeSegment_GlobalID\" true true false 4 Long 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,PipeSegment_GlobalID,-1,-1;Pipe_GlobalID \"Pipe_GlobalID\" true true false 4 Long 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,Pipe_GlobalID,-1,-1;PipeSegment_GlobalID_1 \"PipeSegment_GlobalID\" true true false 4 Long 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,PipeSegment_GlobalID_1,-1,-1;PipeSegment_GIS_GlobalID \"PipeSegment_GIS_GlobalID\" true true false 4 Long 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,PipeSegment_GIS_GlobalID,-1,-1;CoordinateNumber \"CoordinateNumber\" true true false 4 Long 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,CoordinateNumber,-1,-1;Pipe_MeasuredLength \"Pipe_MeasuredLength\" true true false 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,Pipe_MeasuredLength,-1,-1;Status \"Status\" true true false 8000 Text 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,Status,-1,-1;PipeSpecification \"PipeSpecification\" true true false 8000 Text 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,PipeSpecification,-1,-1;InsideDiameter \"InsideDiameter\" true true false 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,InsideDiameter,-1,-1;DesignPressureStandard \"DesignPressureStandard\" true true false 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,DesignPressureStandard,-1,-1;Material \"Material\" true true false 8000 Text 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,Material,-1,-1;Roughness \"Roughness\" true true false 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,Roughness,-1,-1;OperatingPressure \"OperatingPressure\" true true false 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,OperatingPressure,-1,-1;InstallationDate \"InstallationDate\" true true false 8000 Text 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,InstallationDate,-1,-1;Owner \"Owner\" true true false 8000 Text 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,Owner,-1,-1;XCoord \"XCoord\" true true false 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,XCoord,-1,-1;YCoord \"YCoord\" true true false 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,YCoord,-1,-1;PipeSegment_MeasuredLength \"PipeSegment_MeasuredLength\" true true false 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched,PipeSegment_MeasuredLength,-1,-1;Status_1 \"Status\" true true false 8000 Text 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_Dissolve,Status,-1,-1;Material_1 \"Material\" true true false 8000 Text 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_Dissolve,Material,-1,-1;OperatingPressure_1 \"OperatingPressure\" true true false 8 Double 0 0 ,First,#,C:\\Users\\rgys\\Desktop\\XXX\\GIS\\Default.gdb\\PS_P_Brugge_Enriched_Dissolve,OperatingPressure,-1,-1", "WITHIN", "", "")
# Process: Make Feature Layer (2)
arcpy.MakeFeatureLayer_management(PS_P_Brugge_Enriched_DissolvedBuffer_temp, PS_P_Brugge_Enriched_DissolvedBuffer_temp2, "Status = Status_1 AND Material = Material_1 AND OperatingPressure = OperatingPressure_1", "", "OBJECTID OBJECTID VISIBLE NONE;Shape Shape VISIBLE NONE;Join_Count Join_Count VISIBLE NONE;TARGET_FID TARGET_FID VISIBLE NONE;JOIN_FID JOIN_FID VISIBLE NONE;Shape_Length Shape_Length VISIBLE NONE;PipeSegment_GlobalID PipeSegment_GlobalID VISIBLE NONE;Pipe_GlobalID Pipe_GlobalID VISIBLE NONE;PipeSegment_GlobalID_1 PipeSegment_GlobalID_1 VISIBLE NONE;PipeSegment_GIS_GlobalID PipeSegment_GIS_GlobalID VISIBLE NONE;CoordinateNumber CoordinateNumber VISIBLE NONE;Pipe_MeasuredLength Pipe_MeasuredLength VISIBLE NONE;Status Status VISIBLE NONE;PipeSpecification PipeSpecification VISIBLE NONE;InsideDiameter InsideDiameter VISIBLE NONE;DesignPressureStandard DesignPressureStandard VISIBLE NONE;Material Material VISIBLE NONE;Roughness Roughness VISIBLE NONE;OperatingPressure OperatingPressure VISIBLE NONE;InstallationDate InstallationDate VISIBLE NONE;Owner Owner VISIBLE NONE;XCoord XCoord VISIBLE NONE;YCoord YCoord VISIBLE NONE;PipeSegment_MeasuredLength PipeSegment_MeasuredLength VISIBLE NONE;Status_1 Status_1 VISIBLE NONE;Material_1 Material_1 VISIBLE NONE;OperatingPressure_1 OperatingPressure_1 VISIBLE NONE")
# Process: Copy Features (2)
arcpy.CopyFeatures_management(PS_P_Brugge_Enriched_DissolvedBuffer_temp2, PS_P_Brugge_Enriched_DissolvedBuffer__2_, "", "0", "0", "0")
# Process: Dissolve (4)
arcpy.Dissolve_management(PS_P_Brugge_Enriched_DissolvedBuffer__2_, PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved, "JOIN_FID;Status;Material;OperatingPressure", "Pipe_MeasuredLength SUM;PipeSegment_GlobalID COUNT", "MULTI_PART", "DISSOLVE_LINES")
# Process: Add Field (2)
arcpy.AddField_management(PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved, "AssetUnit_GlobalID_temp", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
# Process: Calculate Field (2)
arcpy.CalculateField_management(PS_P_Brugge_Enriched_DissolvedBuffer_Dissolved__3_, "AssetUnit_GlobalID_temp", "Cluster(!JOIN_FID!)", "PYTHON", "def Cluster(y):\\n\\n return y\\n")
# Process: Copy Features (3)
arcpy.CopyFeatures_management(PS_P_Brugge_Enriched_DissolvedBuffer__2_, PS_P_Brugge_Enriched_DissolvedBufferTemp, "", "0", "0", "0")
# Process: Add Field (3)
arcpy.AddField_management(PS_P_Brugge_Enriched_DissolvedBufferTemp, "AssetUnit_GlobalID_temp", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
# Process: Calculate Field (3)
arcpy.CalculateField_management(PS_P_Brugge_Enriched_DissolvedBuffer__4_, "AssetUnit_GlobalID_temp", "Cluster(!JOIN_FID!)", "PYTHON", "def Cluster(y):\\n\\n return y\\n")
# Process: Export Feature Attribute to ASCII
arcpy.ExportXYv_stats(PS_P_Brugge_Enriched_DissolvedBufferTemp__2_, "OBJECTID;Join_Count;TARGET_FID;JOIN_FID;Shape_Length;PipeSegment_GlobalID;Pipe_GlobalID;PipeSegment_GlobalID_1;PipeSegment_GIS_GlobalID;CoordinateNumber;Pipe_MeasuredLength;Status;PipeSpecification;InsideDiameter;DesignPressureStandard;Material;Roughness;OperatingPressure;InstallationDate;Owner;XCoord;YCoord;PipeSegment_MeasuredLength;Status_1;Material_1;OperatingPressure_1;AssetUnit_GlobalID_temp", "SEMI-COLON", PS_P_Brugge_Enriched_DissolvedBuffer, "ADD_FIELD_NAMES")
arcpy.da.SearchCursor()
and how to load info from cursors into a python dictionary that can be used to hold your parameters