I tried to run this script for converting a batch of shp files in a folder... But i receive error msg posted below... Kindly suggest...
import arcpy
# Set environment settings
arcpy.env.workspace = r"D:\Work\Test"
#Output Path
outKML = r"D:\Work\Test\new"
# Variables Defined
composite = 'NO_COMPOSITE'
pixels = 2048
dpi = 96
clamped = 'CLAMPED_TO_GROUND'
scale = 10000
for layer in arcpy.ListFiles():
arcpy.MakeFeatureLayer_management(layer, Flayer)
arcpy.LayerToKML_conversion(Flayer, outKML,scale, composite,
'', pixels, dpi, clamped)
else:
arcpy.AddMessage('There are no layer files in '+arcpy.env.workspace+'.')
Error :
Traceback (most recent call last):
File "D:\Work\Test\Test.py", line 13, in <module>
arcpy.MakeFeatureLayer_management(layer, Flayer)
NameError: name 'Flayer' is not defined
May I suggest that you use python syntax highlighting (in the advanced editor) to post code.
But, your problem seems obvious. Where are you defining what the variable Flayer is.
Or do you want to call the output feature layer "Flayer".
I'm trying to convert the Shapefile to layer and then to kml....I'm not sure whether the flow is correct .... Pls Suggest
In that script you are not assigning Flayer to be anything.
Therefore, when it appear in the MakeFeatureLayer tool, it is not assigned (does not exist).
And, what is arcpy.ListFiles() returning? A list of what?. Shapefiles?
You should use ListFeatureClasses rather than ListFiles, because ListFiles will return all individual files from a shapefile (e.g. shp, and shx, and dbf, etc.).
Also, as your code is now, you will overwrite your output KML over and over because you don't change the name on each iteration.