<?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: clip from multiple folders and gdb in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226274#M17523</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like the code will fail at line 11 above in the 'fc_output' variable since 'filenames' is not yet defined.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os, arcpy&amp;nbsp;&amp;nbsp;&amp;nbsp; 
from arcpy import env&amp;nbsp; 
&amp;nbsp; 
workspace = "D:\\GIS\\Zone1\\Zone1A"&amp;nbsp;&amp;nbsp;&amp;nbsp; 
clipfeature = "D:\\GIS\\Temp\\clip.gdb\\BorderClip"&amp;nbsp; 
outputdatabase = "D:\\GIS\\Output\\clip.gdb"

walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="All")
for dirpath, dirnames, filenames in walk:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in filenames:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inputFC = os.path.join(workspace, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_output = os.path.join(outputdatabase, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unique_name = arcpy.CreateUniqueName(fc_output)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_analysis(inputFC, clipfeature, unique_name)&amp;nbsp; 

print "Finished"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:01:19 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-11T11:01:19Z</dc:date>
    <item>
      <title>clip from multiple folders and gdb</title>
      <link>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226272#M17521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;With lots of help I have a script that search my folder and gdb for featureclasses and rename them. That script works great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The next step in my workflow will by clipping. I want the clip feature to clip all my featuresclasses in all folders and gdb’s. I am using the rename script as kind of a template.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The problem now is in a unique output name&lt;/STRONG&gt; (the name of the featuresclasses in the gdb are the same (not the factor only the name). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The script I have so far is wrong but it I was hoping it could do the trick if I set it right.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;So far the error is in line 10 the join is not working I do not know if the unique_name will work&lt;/STRONG&gt; but that is my solution for the unique name problem. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW I was think about a script that looks at the extend (clip feature) first and if true then clip and if not nothing.&amp;nbsp; I am over my head already and I have a script that cleans my gdb’s of empty featureclasses. So for now for my this is ok.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os 
import arcpy&amp;nbsp; 
from arcpy import env


workspace = "D:\\GIS\\Zone1\\Zone1A"&amp;nbsp; 
feature_classes = []
clipfeature = "D:\\GIS\\Temp\\clip.gdb\\BorderClip"
outputdatabase = "D:\\GIS\\Output\\clip.gdb"
walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="All")&amp;nbsp; 
fc_output = os.path.join(outputdatabase,filenames)
unique_name = arcpy.CreateUniqueName(fc_output)


for dirpath, dirnames, filenames in walk:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in filenames:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feature_classes.append(os.path.join(dirpath, filename))&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
#&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("clipping: " + feature_classes)
arcpy.Clip_analysis(feature_classes, clipfeature, ounique_name)




&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greeting Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:01:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226272#M17521</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2021-12-11T11:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: clip from multiple folders and gdb</title>
      <link>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226273#M17522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Peter,&lt;/P&gt;&lt;P&gt;just after a short look, it seems that you are referencing the variable "filenames" in line 11 before even creating it. that may cause your script to fail at this point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Philippe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jan 2015 14:36:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226273#M17522</guid>
      <dc:creator>PhilippeRieffel1</dc:creator>
      <dc:date>2015-01-21T14:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: clip from multiple folders and gdb</title>
      <link>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226274#M17523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Peter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like the code will fail at line 11 above in the 'fc_output' variable since 'filenames' is not yet defined.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os, arcpy&amp;nbsp;&amp;nbsp;&amp;nbsp; 
from arcpy import env&amp;nbsp; 
&amp;nbsp; 
workspace = "D:\\GIS\\Zone1\\Zone1A"&amp;nbsp;&amp;nbsp;&amp;nbsp; 
clipfeature = "D:\\GIS\\Temp\\clip.gdb\\BorderClip"&amp;nbsp; 
outputdatabase = "D:\\GIS\\Output\\clip.gdb"

walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="All")
for dirpath, dirnames, filenames in walk:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in filenames:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inputFC = os.path.join(workspace, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_output = os.path.join(outputdatabase, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unique_name = arcpy.CreateUniqueName(fc_output)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_analysis(inputFC, clipfeature, unique_name)&amp;nbsp; 

print "Finished"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:01:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226274#M17523</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T11:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: clip from multiple folders and gdb</title>
      <link>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226275#M17524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jake,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for the corrections. in line 11 in your script is 1 mistake workspace must by dirpath. then the scripts works great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os, arcpy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
from arcpy import env


workspace = "D:\\Documenten\\GIS\\Duitsland\\N47GDB3"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
clipfeature = "D:\\Documenten\\GIS\\Duitsland\\clip.gdb\\BorderClip"&amp;nbsp;&amp;nbsp;&amp;nbsp; 
outputdatabase = "D:\\Documenten\\GIS\\Duitsland\\N47GDB3\\clip.gdb"&amp;nbsp; 
&amp;nbsp; 
walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="All")&amp;nbsp; 
for dirpath, dirnames, filenames in walk:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in filenames:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inputFC = os.path.join(dirpath, filename)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_output = os.path.join(outputdatabase, filename)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unique_name = arcpy.CreateUniqueName(fc_output)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_analysis(inputFC, clipfeature, unique_name)&amp;nbsp;&amp;nbsp; 


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:01:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226275#M17524</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2021-12-11T11:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: clip from multiple folders and gdb</title>
      <link>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226276#M17525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For those who like the script this is my model.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greetings Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Jan 2015 13:23:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-from-multiple-folders-and-gdb/m-p/226276#M17525</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2015-01-22T13:23:31Z</dc:date>
    </item>
  </channel>
</rss>

