<?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 Trouble with loops in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trouble-with-loops/m-p/260843#M20051</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having trouble setting up a basic loop. Most of the examples I'm finding online are either rudimentary "this is what a loop does" examples or don't seem to apply to what I'm doing. It's entirely probable that my workflow is just still not right. Please take a look at my code and help me become less of an amateur!&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have multiple processes to run on multiple files of the same type. So I build out the workflow in ModelBuilder and export that to a python script. In this case, I'm running the Minimum Bounding Geometry tool on a multipoint feature, converting the resultant vertices to points, then adding XY fields. It works great running in ModelBuilder or as a script on a single file, and the code is below in bold; however, I want to run this tool on a whole folder's worth of files.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# Local variables:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;N2E100 = "D:\\Broomfield.Lidar\\Projection\\ReProject.gdb\\N2E100"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;N2E100_MinimumBoundingGeomet = "D:\\Broomfield.Lidar\\GeometryResults.gdb\\N2E100_MinimumBoundingGeomet"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;N2E100_MinimumBoundingGeomet1 = "D:\\Broomfield.Lidar\\GeometryResults.gdb\\N2E100_MinimumBoundingGeomet1"&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# Process: Minimum Bounding Geometry&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arcpy.MinimumBoundingGeometry_management(N2E100, N2E100_MinimumBoundingGeomet, "RECTANGLE_BY_AREA", "ALL", "", "NO_MBG_FIELDS")&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# Process: Feature Vertices To Points&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arcpy.FeatureVerticesToPoints_management(N2E100_MinimumBoundingGeomet, N2E100_MinimumBoundingGeomet1, "ALL")&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# Process: Add XY Coordinates&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arcpy.AddXY_management(N2E100_MinimumBoundingGeomet1)&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm quite familiar with the syntax of loops and how they work in theory, but it's putting the loops into practice that I struggle with.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Feb 2015 20:59:08 GMT</pubDate>
    <dc:creator>alexbullen</dc:creator>
    <dc:date>2015-02-05T20:59:08Z</dc:date>
    <item>
      <title>Trouble with loops</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-loops/m-p/260843#M20051</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having trouble setting up a basic loop. Most of the examples I'm finding online are either rudimentary "this is what a loop does" examples or don't seem to apply to what I'm doing. It's entirely probable that my workflow is just still not right. Please take a look at my code and help me become less of an amateur!&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have multiple processes to run on multiple files of the same type. So I build out the workflow in ModelBuilder and export that to a python script. In this case, I'm running the Minimum Bounding Geometry tool on a multipoint feature, converting the resultant vertices to points, then adding XY fields. It works great running in ModelBuilder or as a script on a single file, and the code is below in bold; however, I want to run this tool on a whole folder's worth of files.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# Local variables:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;N2E100 = "D:\\Broomfield.Lidar\\Projection\\ReProject.gdb\\N2E100"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;N2E100_MinimumBoundingGeomet = "D:\\Broomfield.Lidar\\GeometryResults.gdb\\N2E100_MinimumBoundingGeomet"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;N2E100_MinimumBoundingGeomet1 = "D:\\Broomfield.Lidar\\GeometryResults.gdb\\N2E100_MinimumBoundingGeomet1"&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# Process: Minimum Bounding Geometry&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arcpy.MinimumBoundingGeometry_management(N2E100, N2E100_MinimumBoundingGeomet, "RECTANGLE_BY_AREA", "ALL", "", "NO_MBG_FIELDS")&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# Process: Feature Vertices To Points&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arcpy.FeatureVerticesToPoints_management(N2E100_MinimumBoundingGeomet, N2E100_MinimumBoundingGeomet1, "ALL")&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;# Process: Add XY Coordinates&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arcpy.AddXY_management(N2E100_MinimumBoundingGeomet1)&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm quite familiar with the syntax of loops and how they work in theory, but it's putting the loops into practice that I struggle with.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 20:59:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-loops/m-p/260843#M20051</guid>
      <dc:creator>alexbullen</dc:creator>
      <dc:date>2015-02-05T20:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with loops</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-loops/m-p/260844#M20052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alex,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you trying to run this on every feature class within a single geodatabase?&amp;nbsp; Or, are you trying to run this on feature classes in different geodatabases? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is an example on how you can do this for every feature class within a single geodatabase.&amp;nbsp; You can use the arcpy.ListFeatureClasses function to create a list of all the feature classes.&amp;nbsp; You can then run a 'for' loop on each feature class within this list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env

env.workspace = r"D:\Broomfield.Lidar\Projection\ReProject.gdb"

lstFCs = arcpy.ListFeatureClasses()
for fc in lstFCs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MinimumBoundingGeometry_management(fc, fc + "_MinimumBoundingGeomet", "RECTANGLE_BY_AREA", "ALL", "", "NO_MBG_FIELDS")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureVerticesToPoints_management(fc, fc + "_MinimumBoundingVertices", "ALL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddXY_management(fc + "_MinimumBoundingVertices")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:48:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-loops/m-p/260844#M20052</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T12:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with loops</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-loops/m-p/260845#M20053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perfecto! Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Feb 2015 18:50:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-loops/m-p/260845#M20053</guid>
      <dc:creator>alexbullen</dc:creator>
      <dc:date>2015-02-12T18:50:25Z</dc:date>
    </item>
  </channel>
</rss>

