0

I have a script that buffers a selected point, and intersects that buffer with features that the user inputs. I would like to convert the table outputted from the Intersect process into a excel file. This is what I have so far:

import arcpy


#Set to current mxd and dataframe
mxd = arcpy.mapping.MapDocument ('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]

# Set overwrite option
arcpy.env.overwriteOutput = True
arcpy.env.workspace ="C:\Users\pierrej\Desktop\GIS Data"
wrk=arcpy.env.workspace
arcpy.AddMessage("Workspace added")

try:
# Get the input parameters for the Selection Tool
FClass = arcpy.GetParameterAsText(0)
Field = arcpy.GetParameterAsText(1)
Feature = arcpy.GetParameterAsText(2)
outPath = arcpy.GetParameterAsText(3)
bufferDistance = arcpy.GetParameterAsText(4)
IntersectFeature = arcpy.GetParameterAsText(5)
SpecifiedSites = arcpy.GetParameterAsText(6)

where_clause = """{} = {}""".format(arcpy.AddFieldDelimiters(FClass, Field),Feature)   # I have added extra pair of single quotes for selecting strings
arcpy.AddMessage(where_clause)

# Select the site 
arcpy.SelectLayerByAttribute_management(FClass,"NEW_SELECTION", where_clause) 

# write selected features to a new featureclass
arcpy.CopyFeatures_management(FClass, "SelectionSites")

# Report a success message    
arcpy.AddMessage("Site selected!")


#Zooming to a selection set for the specific layer
df.zoomToSelectedFeatures()
df.scale = 300000
arcpy.RefreshActiveView()

# Run the Buffer tool 
AreaOfInterest = arcpy.Buffer_analysis(FClass, outPath, bufferDistance)

# Report a success message    
arcpy.AddMessage("Buffer made!")

#Clear Selected features 
arcpy.SelectLayerByAttribute_management(FClass, "CLEAR_SELECTION")

# Report a success message    
arcpy.AddMessage("Selection cleared!")

# Run the Intersect analysis
List = arcpy.Intersect_analysis([IntersectFeature, AreaOfInterest], SpecifiedSites, "ALL", "", "INPUT")

# Report a success message    
arcpy.AddMessage("Intersect analysis made!")


#Process: Export to CSV table
arcpy.TableToExcel_conversion(List, wrk, "Table.csv", "COMMA")


# Report a success message    
arcpy.AddMessage("Results exported to a Excel file!")

except:
 # Report an error messages
 arcpy.AddError("Could not complete")

 # Report any error messages that the tool might have generated    
 arcpy.AddMessage(arcpy.GetMessages())

So I'm trying a couple of things and I keep getting this error message. ERROR 000732: Output Location: Dataset C:\Users\pierrej\Desktop\GIS Data does not exist or is not supported. Even if I change the output path to a folder without spaces I get the same thing.

  • 1
    For which line of code do you get the error message? – BERA Aug 10 '18 at 20:39
3

Try adding r to the path:

arcpy.env.workspace =r"C:\Users\pierrej\Desktop\GIS Data"

or the backslashes may be interpreted as escape characters.

Correct syntax for Table to Excel is:

TableToExcel_conversion(Input_Table, Output_Excel_File, {Use_field_alias_as_column_header}, {Use_domain_and_subtype_description})

You are providing a path as Output_Excel_File when it should be a file.

You should not use List as a variable name since list is used as a list constructor.

  • I added the '.xls' part but it's still giving me the invalid parameters error. I'm under the impression that it has to do with the input table (it's an .shp file) – Jonathan P Aug 13 '18 at 16:33
0

so I added r to the path, changed to synthax for

# Run the Intersect analysis
Input_Table = arcpy.Intersect_analysis([IntersectFeature, AreaOfInterest], SpecifiedSites, "ALL", "", "INPUT")

# Report a success message    
arcpy.AddMessage("Intersect analysis made!")

#Process: Export to CSV table
arcpy.TableToExcel_conversion(Input_Table, "Ouput_Excel_File")

# Report a success message    
arcpy.AddMessage("Results exported to a Excel file!")

The table to Excel conversion still fails to execute. The message is: Invalid parameters.

  • Your answer should be an edit to your original question and include the error message you get now. "Ouput_Excel_File" should be "Ouput_Excel_File.xls" – BERA Aug 13 '18 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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