AnsweredAssumed Answered

Feature Class Z to ASCII File Names

Question asked by Rlnasral on Mar 12, 2019
Latest reply on Mar 12, 2019 by Dan_Patterson

Hello All, 
I have a seemingly minor problem which likely requires some Python coding. I am not currently familiar with python (more of a Matlab person), and was wondering if anyone had any advice. 
I am attempting to use the Feature Class Z to ASCII tool to make text files with my Z elevations. This tool performs correctly in all respects except 1: It names the text files based on the OID (or FID) column instead of a unique column (named 'Id') that is in my attribute table. Up until this point we have had a separate, hand made file that converts from FID to Id in subsequent analysis, but it is incredibly prone to error and confusing to use. 
Is there any simple way to modify this tool so that it outputs names based on a chosen column instead of the default OID column? 
I  have attached a zip file of a z-interpolated shapefile below. The 'Id' column is the desired naming column. 

The Code is below:

Name: FeatureClassZToASCII Example
Description: This script demonstrates how to use the
FeatureClassZToASCII tool to create generate files for all
z-aware point features in a given workspace.
import arcpy
import exceptions, sys, traceback
from arcpy import env

# Obtain a license for the ArcGIS 3D Analyst extension
# Set environment settings
env.workspace = 'C:/data'
# List all points in the target workspace
fcList = arcpy.ListFeatureClasses("*", "POINT")
if fcList:
# Set Local Variables
outFolder = "C:/output"
outFormat = "GENERATE"
delimeter = "SPACE"
decimal = "FIXED"
digits = 3
dec_sep = "DECIMAL_POINT"
for fc in fcList:
# Use Describe method to evaluate whether the feature class is z-aware
desc = arcpy.Describe(fc)
if desc.hasZ == True:
# Define the output file name by replacing '.shp' with _ascii.txt
outName = fc.replace('.shp', '') + "_ascii.txt"
#Execute FeatureClassZToASCII_3d
arcpy.FeatureClassZToASCII_3d(fc, outFolder, outName, outFormat, delimeter, decimal, digits, dec_sep)
print "There are no feature classes in the " + env.workspace + " directory."

except arcpy.ExecuteError:
print arcpy.GetMessages()
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate error information into message string
pymsg = 'PYTHON ERRORS:\nTraceback info:\n{0}\nError Info:\n{1}'\
.format(tbinfo, str(sys.exc_info()[1]))
msgs = 'ArcPy ERRORS:\n {0}\n'.format(arcpy.GetMessages(2))
# Return python error messages for script tool or Python Window


I assume that the root of the problem is the 'fclist' variable. Any help in solving this problem is appreciated. 

Ps. Bonus points if anyone can give some guidance on how to include this as a tool in arcgis so I don't have to run it in an IDE