2

I'm am creating a script that will allow a user to add XY coordinates to a point layer, then export (along with any addition user selected fields) to Excel. I am getting stuck on the iteration of the selected fields and how to map them to prepare to export to Excel. I have a parameter that derives the field names from the input point layer and the user can tick each field they wish to include in the Excel export.

1
  • Can you add a sample of your code to your question? This might help you to get a good answer.
    – GeoJohn
    Commented Oct 24, 2014 at 16:10

3 Answers 3

2

I found that I simply needed to split the field selections and then iterate through the list using field mapping.

paramInWells = arcpy.GetParameterAsText(0)
paramInFields = arcpy.GetParameterAsText(1)
paramInFieldList = paramInFields.split(";")
paramOutExcel = arcpy.GetParameterAsText(2)

arcpy.SetProgressorLabel("Processing...")
arcpy.AddMessage("\nAdding XY coordinates")

fms = arcpy.FieldMappings()
for field in paramInFieldList:
    fieldName = arcpy.FieldMap()
    fieldName.addInputField(paramInWells, field)
    fms.addFieldMap(fieldName)

arcpy.FeatureClassToFeatureClass_conversion(paramInWells, "in_memory", "XYCoords_Tmp", field_mapping=fms)

paramOutXyTemp = "in_memory\\XYCoords_Tmp"
arcpy.AddXY_management(paramOutXyTemp)
arcpy.AddMessage("\nCreating Excel document")
arcpy.TableToExcel_conversion(paramOutXyTemp, paramOutExcel)
0

One option you could try:

  1. Make feature layer of your source field layer
  2. Turn off fields or make them HIDDEN via the

fieldInfo.setVisible()

Method sourcing from the user defined parameter.

Turning fields on and off using arcpy

FieldInfo (arcpy)

  1. Finally, you may use the Table to Excel method for creating the excel table from the feature layer as the input table
0

you could also use the built in tool "export feature attribute to ascii". This is ascii file and not excel, but very easy to import in excel. It adds XY coordinates automatically and you can check the fields that you want to keep.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.