I have a script that takes in a line, and creates a certain polygon based on this.
My code obtaining the input information is as follows:
inFC = arcpy.GetParameterAsText(0)
hasClearway = arcpy.GetParameterAsText(1)
hasHighDivergence = arcpy.GetParameterAsText(2)
outFC = arcpy.GetParameterAsText(3)
fcName = outFC.rpartition("\\")[2]
fcPath = outFC.rpartition("\\")[0]
outFC = arcpy.CreateFeatureclass_management(fcPath, fcName, "POLYGON", inFC, "DISABLED", "DISABLED", inFC)
The polygon is finally created from an array and inserted into outFC
runwaypolygon = arcpy.Polygon(polygon_array)
cursor = arcpy.da.InsertCursor(outFC, ['SHAPE@'])
cursor.insertRow([runwaypolygon])
However I am getting the error 20469, "An Error Occured trying to save the object named X", when trying to set the output FC, see below screenshot:
I have looked into this http://support.esri.com/de/knowledgebase/techarticles/detail/20469 but this has not shed any light on the issue. Two further points:
(1) I have successfully used this method with an object of exactly the same type (a polygon produced in the same way).
(2) The script works fine when I ask the user to specify output file location and name separately, as here:
inFC = arcpy.GetParameterAsText(0)
hasClearway = arcpy.GetParameterAsText(1)
hasHighDivergence = arcpy.GetParameterAsText(2)
outFC_location = arcpy.GetParameterAsText(3)
fcName = (arcpy.GetParameterAsText(4))
outFC = arcpy.CreateFeatureclass_management(outFC_location, fcName, "POLYGON")
What is the error in my code or my approach?
1 Answer 1
Regardless of where the error occurs, it seems that the data type of your outFC
parameter is wrong, you've probably chosen 'Workspace' instead of 'Feature Class'. In the script tool's interface, choose 'Feature Class' as data type:
-
I had it set to "Workspace or feature class", however setting explicitly to "feature class" has worked. Many thanks.acolls_badger– acolls_badger2016年01月06日 10:07:38 +00:00Commented Jan 6, 2016 at 10:07
-
@branches - I don't have that option with 10.3.1, only 'Workspace', 'Workspace or feature dataset' and 'Workspace or Raster Catalog'. Maybe you could have changed the 'Save as data type' option from 'Geodatabases' to 'Feature classes' in the parameter's browse window. 'Feature classes' is a safer choice anyway if it's the only valid option for your script!GISGe– GISGe2016年01月06日 10:14:13 +00:00Commented Jan 6, 2016 at 10:14
fcPath, fcName = os.path.split(outFC)
?