<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating KML files and store them in the related folders in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/creating-kml-files-and-store-them-in-the-related/m-p/1143011#M63721</link>
    <description>&lt;P&gt;it is using your last folder I presume. how are you supposed to know which folder to put the files in in order to change the "folder" name?&amp;nbsp; You will have to maintain an index number referencing the folder or more simply, combine the folder creation with the kml export if they are synced&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Feb 2022 11:54:31 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2022-02-11T11:54:31Z</dc:date>
    <item>
      <title>Creating KML files and store them in the related folders</title>
      <link>https://community.esri.com/t5/python-questions/creating-kml-files-and-store-them-in-the-related/m-p/1142974#M63720</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I have a properties feature class and want to use this to create a kml file for each property and store it in the related region folder. I created a python script, but it put all the kml files in one folder and the rest are empty.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me fix my script?&lt;/P&gt;&lt;P&gt;Maryam&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
arcpy.env.overwriteOutput = True

# settings
inputFC = r"\\D\Asset.sde\DBO.asset"
field_name=["Property_code","Property_Name","Region"]
output_location = r"\\D\Country\KML"

print "Starting"

# create list of unique properties codes and regions 
lst_property = []
lst_regions= []
cursor = arcpy.SearchCursor(inputFC)
for row in cursor:
    lst_property.append(row.getValue(field_name[0]))
    lst_regions.append(row.getValue(field_name[2]))
del cursor
del row
lst_property = list(set(lst_property))
lst_regions = list(set(lst_regions))


for regions in lst_regions:
    field1 = arcpy.AddFieldDelimiters(inputFC, field_name[2])
    where ="\"{0}\" = '{1}'".format(field1, regions)
    folder=os.path.join(output_location,regions)
    if not os.path.exists(folder):
        os.makedirs(folder)
    folder=r"{}\{}".format(output_location,regions)
   


#loop through properties
for Properties in lst_property:
    field = arcpy.AddFieldDelimiters(inputFC, field_name[0])
    where ="\"{0}\" = '{1}'".format(field, Properties)
    arcpy.MakeFeatureLayer_management(inputFC, "lyr", where)
    kmz_file = os.path.join(folder,"{0}.kmz".format(Properties))
    arcpy.LayerToKML_conversion("lyr", kmz_file)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 07:52:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-kml-files-and-store-them-in-the-related/m-p/1142974#M63720</guid>
      <dc:creator>MaryamPanji</dc:creator>
      <dc:date>2022-02-11T07:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating KML files and store them in the related folders</title>
      <link>https://community.esri.com/t5/python-questions/creating-kml-files-and-store-them-in-the-related/m-p/1143011#M63721</link>
      <description>&lt;P&gt;it is using your last folder I presume. how are you supposed to know which folder to put the files in in order to change the "folder" name?&amp;nbsp; You will have to maintain an index number referencing the folder or more simply, combine the folder creation with the kml export if they are synced&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 11:54:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-kml-files-and-store-them-in-the-related/m-p/1143011#M63721</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-02-11T11:54:31Z</dc:date>
    </item>
  </channel>
</rss>

