I ran the ModelBuilder to Python script and now my script won't run. It has a problem with the local variables. Is there a fast way to declare all the variables even though some of them are created after the analysis is done?
import arcpy
import os
import sys
# Script arguments
MapUnitPolys = arcpy.GetParameterAsText(0)
if MapUnitPolys == '#' or not MapUnitPolys:
MapUnitPolys = "MapUnitPolys" # provide a default value if unspecified
PolygonNeighbor_TableSelect1 = arcpy.GetParameterAsText(1)
if PolygonNeighbor_TableSelect1 == '#' or not PolygonNeighbor_TableSelect1:
PolygonNeighbor_TableSelect1 = "C:/ArcGIS/Default.gdb/PolygonNeighbor_TableSelect1" # provide a default value if unspecified
MapUnitPolys_CopyFeatures5 = arcpy.GetParameterAsText(2)
if MapUnitPolys_CopyFeatures5 == '#' or not MapUnitPolys_CopyFeatures5:
MapUnitPolys_CopyFeatures5 = "C:/ArcGIS/Default.gdb/MapUnitPolys_CopyFeatures5" # provide a default value if unspecified
# Local variables:
MapUnitPolys = MapUnitPolys
Polygon_Neighbors = Polygon_Neighbor_Table
MapUnitPolys__2_ = "MapUnitPolys"
MapUnitPolys__4_ = MapUnitPolys__2_
MapUnitPolys_PolygonNeighbor1 = "MapUnitPolys_PolygonNeighbor1"
MapUnitPolys_PolygonNeighbor1__2_ = MapUnitPolys_PolygonNeighbor1
Polygon_Neighbor_Table = "C:/ArcGIS/Default.gdb/PolygonNeighbor"
MapUnitPolys__3_ = MapUnitPolys__4_
MapUnitPolys__5_ = "MapUnitPolys"
MapUnitPolys__6_ = MapUnitPolys__5_
# Process: Polygon Neighbors
arcpy.PolygonNeighbors_analysis(MapUnitPolys, Polygon_Neighbor_Table, "OBJECTID;MapUnit", "NO_AREA_OVERLAP", "BOTH_SIDES", "", "METERS", "SQUARE_METERS")
# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management(MapUnitPolys_PolygonNeighbor1, "NEW_SELECTION", "src_MapUnit = nbr_MapUnit")
# Process: Table Select
arcpy.TableSelect_analysis(MapUnitPolys_PolygonNeighbor1__2_, PolygonNeighbor_TableSelect1, "")
# Process: Add Join
arcpy.AddJoin_management(MapUnitPolys__2_, "OBJECTID", PolygonNeighbor_TableSelect1, "src_OBJECTID", "KEEP_ALL")
# Process: Select Layer By Attribute (2)
arcpy.SelectLayerByAttribute_management(MapUnitPolys__4_, "NEW_SELECTION", "PolygonNeighbor_TableSelect1.src_OBJECTID IS NOT NULL")
# Process: Copy Features
arcpy.CopyFeatures_management(MapUnitPolys__3_, MapUnitPolys_CopyFeatures5, "", "0", "0", "0")
# Process: Remove Join
arcpy.RemoveJoin_management(MapUnitPolys__5_, "")
error:
Traceback (most recent call last):
File "C:\Users\Desktop\help.py", line 28, in
MapUnitPolys_CopyFeatures5 = arcpy.GetParameterAsText(2)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\__init__.py", line 663, in GetParameterAsText
return gp.getParameterAsText(index)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 233, in getParameterAsText
self._gp.GetParameterAsText(*gp_fixargs(args, True)))
RuntimeError: Object: Error in getting parameter as text
Failed to execute (Script3).
No comments:
Post a Comment