<?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 Python if ... then Statement in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186502#M6332</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am attempting to add an If statement to my Python script. What I am wanting to do is query a field in a shapefile and if it returns true delete a different shapefile. The principle idea behind my code is; If "Region" in the Clip_Feature shapefile = 'Murray Inland' then delete the contour shapefile. My problem is I don't know how to get focus onto the the Clip_Feature shapefile.&amp;nbsp; The code I have so far is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, string, os, arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Contours = "\\\\Atlas\\data\\geodata\\state\\contour\\arc"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Crossings = "\\\\Atlas\\data\\geodata\\state\\crossings\\arc"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Contour = "Contour.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Crossing = "Crossing.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;P_L = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Clip_Feature = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature\\Clip_Feature.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FeatureClassToFeatureClass_conversion(Contours, P_L, Contour, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FeatureClassToFeatureClass_conversion(Crossings, P_L, Crossing, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.workspace = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if "Region_No" == 3:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Contour.shp")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Aug 2010 04:29:55 GMT</pubDate>
    <dc:creator>DaveMarkey</dc:creator>
    <dc:date>2010-08-03T04:29:55Z</dc:date>
    <item>
      <title>Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186502#M6332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am attempting to add an If statement to my Python script. What I am wanting to do is query a field in a shapefile and if it returns true delete a different shapefile. The principle idea behind my code is; If "Region" in the Clip_Feature shapefile = 'Murray Inland' then delete the contour shapefile. My problem is I don't know how to get focus onto the the Clip_Feature shapefile.&amp;nbsp; The code I have so far is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, string, os, arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Contours = "\\\\Atlas\\data\\geodata\\state\\contour\\arc"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Crossings = "\\\\Atlas\\data\\geodata\\state\\crossings\\arc"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Contour = "Contour.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Crossing = "Crossing.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;P_L = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Clip_Feature = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature\\Clip_Feature.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FeatureClassToFeatureClass_conversion(Contours, P_L, Contour, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FeatureClassToFeatureClass_conversion(Crossings, P_L, Crossing, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.workspace = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if "Region_No" == 3:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Contour.shp")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 04:29:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186502#M6332</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-08-03T04:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186503#M6333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You need a search cursor to look over the shapefile and see if that value occurs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;in 9.3:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;scursor=gp.SearchCursor(Clip_Feature)
row=scursor.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region_No") == 3:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data \\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Contour.shp")
del scursor
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;in 10:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in arcpy.SearchCursor(Clip_Feature):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.Region_No == 3:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("C:\\Daves_Stuff\\ArcPad_Data \\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Contour.shp")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:27:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186503#M6333</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2021-12-11T09:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186504#M6334</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In your script does the first line restrict the loop to only the reference layer? I need the If statement to look at the referred layer only as there is a master layer in the same directory that would have 'Murray Inland'.&amp;nbsp; This script is part of a geoprocessor model where the 'clip feature' is derived from user input.&amp;nbsp; I have also noticed the 'while' loop significantly increases processing time.&amp;nbsp; Could a 'for' loop be used instead of 'while'? The loop I'm attempting is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldname = "Region"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.workspace = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;shp = gp.ListFeatureClasses()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for shp in shp:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fieldname == 'Murray Inland':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Contour.shp")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This loop has the problem of not being specific to the 'clip feature' layer and also looks at the master layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have attempted to run the supplied while loop script which executes successfully but gives an error that the contour layer does not exist. My complete script is shown below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, string, os, arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Contours = "\\\\Atlas\\data\\geodata\\state\\contour\\arc"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Crossings = "\\\\Atlas\\data\\geodata\\state\\crossings\\arc"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Contour = "Contour.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Crossing = "Crossing.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;P_L = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Clip_Feature = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature\\Clip_Feature.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FeatureClassToFeatureClass_conversion(Contours, P_L, Contour, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FeatureClassToFeatureClass_conversion(Crossings, P_L, Crossing, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.workspace = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;scursor=gp.SearchCursor(Clip_Feature)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;row=scursor.Next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;while row:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'Murray Inland':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data \\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Contour.shp")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del scursor&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 06:21:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186504#M6334</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-08-04T06:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186505#M6335</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think you are going too deep in your workspace. Is '\\Cl ip_Feature' a directory? I thought that was the name of a shapefile. Also you cant do a for loop on at 9.3 cursor. You have to use a while loop. It seems strange but that is changed at 10 so you can use for.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 12:16:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186505#M6335</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2010-08-04T12:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186506#M6336</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;'Clip_Feature' is both a directory and a shapefile within this directory.&amp;nbsp; The file path for this shapefile is; C:\Daves_Stuff\ArcPad_Data\Standard_Layers\Clip_Feature\Clip_Feature.shp&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Aug 2010 00:08:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186506#M6336</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-08-05T00:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186507#M6337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried changing the file path of the gp.workspace but I am still getting the file does not exist error. I have also tested this script with the clip feature being a different region, thus the statement is now false, therefore the contour dataset should not be deleted. The script appears not to be completing (endless loop?).&amp;nbsp; I killed it after a while, changed the clip feature to be again the Murray Inland region and ran the script. The script then deletes the contour dataset but gives the error this layer does not exist.&amp;nbsp; It appears the loop is not ending.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does the reference to 'Clip_Feature' in the search cursor statement restrict the loop to this dataset only?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Aug 2010 03:13:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186507#M6337</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-08-06T03:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186508#M6338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The search cursor will only apply to the single feature class given when the object is created. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So the script deletes the file but still has an error? Could you post the error? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The while shouldnt fall into an infinite loop with such a simple function inside it. 'while row:' is the same as 'while row != none:'. The loop will continue until cursor.Next() returns a result of none. The while row: loop of geoprocessing cursors work like a for row in cursor: on a normal python cursor.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Aug 2010 11:53:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186508#M6338</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2010-08-06T11:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186509#M6339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Detailed below is the error I am recieving.&amp;nbsp; I have confirmed the referred dataset is created in the specified location.&amp;nbsp; That is, the contour dataset is created in the Temp directory.&amp;nbsp; I do not recieve an error when I comment out the while loop section. Could the fact I am dealing with shapefiles cause the problem. Shapefiles are needed as this data is used by ArcPad.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Daves_Stuff\Scripts\Test.py", line 43, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Temp\\Contour.shp")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000732: Input data element: Dataset C:\Temp\Contour.shp does not exist or is not supported&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Delete).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Aug 2010 03:08:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186509#M6339</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-08-09T03:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186510#M6340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Well you could try gp.delete_management(path, "shapefile") which tells the tool explicitly you are deleting a shapefile, or you can try deleting it with os.remove(). With os.remove() you will have to delete all the files that make up the shapefile individually though. os.remove() is pure python and doesnt muck about with the geoprocessor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for ext in [".shp",".shx",".sbn",".dbf",".prj",".sbx"]:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;os.remove("C:\\Temp\\Contour"+ext)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Aug 2010 12:19:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186510#M6340</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2010-08-11T12:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186511#M6341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately this has not fixed my problem. The deleting of the shapefile is not the problem. It is exiting the loop that is the problem.&amp;nbsp; I tried executing this script when the condition evaluates to false and the script appears to go into a never ending loop.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Aug 2010 06:19:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186511#M6341</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-08-26T06:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186512#M6342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Could you post your current code? From what is already posted I cant see why you would fall into infinity.&amp;nbsp; If it finds 'Murray Inland' and executes the for loop or not doesnt matter. It should still exit at the end of the table when row.Next() returns None.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
scursor=gp.SearchCursor(Clip_Feature)
row=scursor.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'Murray Inland':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for ext in [".shp",".shx",".sbn",".dbf",".prj",".sbx"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove("C:\\Temp\\Contour"+ext)
del scursor 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:27:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186512#M6342</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2021-12-11T09:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186513#M6343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can see why it falls into infinitiy.&amp;nbsp; With a While loop on a cursor you must always make sure that before you add any other code that the last line within the while loop is the code that advances the cursor, i.e., "row=scursor.Next()".&amp;nbsp; If this line of code is not at the end of the while loop block the cursor never advances at all within the loop and the while statement never becomes false (i.e., say the first row does not meet your conditiion, but that row is the only row that ever gets evaluated and never stops being evaluated so the loop never ends)&amp;nbsp; The code below is exactly the same as all of the suggestions above but note that the "row=scursor.Next() statement has been repeated inside the while loop and therefore the cursor position now advances with each pass of the while loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
scursor=gp.SearchCursor(Clip_Feature)
row=scursor.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'Murray Inland':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for ext in [".shp",".shx",".sbn",".dbf",".prj",".sbx"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove("C:\\Temp\\Contour"+ext)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row=scursor.Next()
del scursor 
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I cannot see any obvious connection between the trigger row value and the action being done.&amp;nbsp; But I guess if this is what you want, fine.&amp;nbsp; Also, it seem the trigger only needs to occur once, but there is no certainty that there will not be multiple rows that meet the condition.&amp;nbsp; If that is the situation, the loop should be exited after the first instance of completion of the for loop (i.e., put the exit line within the if block at the same level as the for statement prior to the row advance statement).&amp;nbsp; Not sure what Python syntax is for dropping out of a while loop (I'm an ArcObjects guy still and not up to speed on all things Python), but I am sure such a statement exists.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:27:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186513#M6343</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T09:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186514#M6344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To end a loop prematurly is 'break'. Thankfully in v10 we can do away with the while row: thing and go to for row in cursor: I dislike having to manually advance the cursor like that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
scursor=gp.SearchCursor(Clip_Feature)
row=scursor.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'Murray Inland':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for ext in [".shp",".shx",".sbn",".dbf",".prj",".sbx"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove("C:\\Temp\\Contour"+ext)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&amp;nbsp; row=scursor.Next()
del scursor
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:27:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186514#M6344</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2021-12-11T09:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186515#M6345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have finally got this script to execute successfully without error message, but only when the condition is true.&amp;nbsp; When the condition is false I get the error message shown below.&amp;nbsp; I have also include the full script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have kept the delete management statement as I feel this is a much more efficient method of deleting the required shapefile. As previously mentioned, it is not the delete aspect that is the problem but the fact it is not exiting the loop when the condition is false or giving an error message advising the deleted dataset does not exist when the condition is true.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error Message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Daves_Stuff\Scripts\Test.py", line 18, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del scursor&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NameError: name 'scursor' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Full Script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, string, os, arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mooring_Structure = "Mooring_Structure.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;P_L = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Clip_Feature = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature\\Clip_Feature.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FeatureClassToFeatureClass_conversion("\\\\Atlas\\data\\geodata\\statelamblands\\moor_struct\\arc", P_L, Mooring_Structure, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.workspace = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;scursor=gp.SearchCursor(Clip_Feature)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;row=scursor.Next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;while row:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'North Coast':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row=scursor.Next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del scursor&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Aug 2010 23:42:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186515#M6345</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-08-30T23:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186516#M6346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You need to enclose your code in code tags (press the button that looks like "#" on the message buttons and place you code inside the tags).&amp;nbsp; Your error could occur due to not placing the code in the correct indentation level (but I cannot tell since your indentation is lost without the code tags).&amp;nbsp; I have added some exist checks that may solve the error problems.&amp;nbsp; I also believe it should be indented as follows and you should include the break statement after the deletion occurs since there is no point in processeing any more records after the shape file is deleted.:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import sys, string, os, arcgisscripting
gp = arcgisscripting.create(9.3)

Mooring_Structure = "Mooring_Structure.shp"
P_L = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines"
Clip_Feature = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature\\Clip_Feature.shp"
if gp.Exists(Clip_Feature):
&amp;nbsp; gp.FeatureClassToFeatureClass_conversion("\\\\Atlas\\data\\geodata\\statelamblands\\moor_struct\\arc ", P_L, Mooring_Structure, "")

&amp;nbsp; gp.workspace = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature"
&amp;nbsp; scursor=gp.SearchCursor(Clip_Feature)
&amp;nbsp; row=scursor.Next()
&amp;nbsp; while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'North Coast':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.Exists("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&amp;nbsp; row=scursor.Next()
&amp;nbsp; del scursor &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:27:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186516#M6346</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T09:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186517#M6347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks. I have finally got a solution that works when the condition is both true and false.&amp;nbsp; It is the �??Break�?? statement that makes this code execute successfully.&amp;nbsp; That is, exits the loop when the condition is false and prevents the shapefile does not exist error when the condition is true.&amp;nbsp; I have not used the If statement as advised prior to the shapefile creation line as to me this is not logical and the script executes successfully without this IF.&amp;nbsp; I am very surprised at the difficulty of getting a suitable solution to something as basic as an IF�?�THEN statement.&amp;nbsp; If version 10 does not need the 'Break' statement hopefully the IF...THEN statements will be easier.&amp;nbsp; Shown below is my code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys, string, os, arcgisscripting
gp = arcgisscripting.create(9.3)

Mooring_Structure = "Mooring_Structure.shp"
P_L = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines"
Clip_Feature = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature\\Clip_Feature.shp"
gp.FeatureClassToFeatureClass_conversion("\\\\Atlas\\data\\geodata\\statelamblands\\moor_struct\\arc", P_L, Mooring_Structure, "")

gp.workspace = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature"
scursor=gp.SearchCursor(Clip_Feature)
row=scursor.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'South Coast':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; break
row=scursor.Next()
del scursor&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I have got this script to execute successfully I have expanded it to contain multiple true conditions and delete multiple datasets.&amp;nbsp; I am able to do this as a 'While' loop is being utilised.&amp;nbsp; My expanded script is shown below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys, string, os, arcgisscripting
gp = arcgisscripting.create(9.3)

Mooring_Structure = "Mooring_Structure.shp"
P_L = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines"
Clip_Feature = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature\\Clip_Feature.shp"
gp.FeatureClassToFeatureClass_conversion("\\\\Atlas\\data\\geodata\\statelamblands\\moor_struct\\arc", P_L, Mooring_Structure, "")

gp.workspace = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature"
scursor=gp.SearchCursor(Clip_Feature)
row=scursor.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'North Coast':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'Murray Inland':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Contour.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'South Coast':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; break
row=scursor.Next()
del scursor&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:27:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186517#M6347</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2021-12-11T09:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186518#M6348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your code is indented incorrectly and the way you have written your code does not process the while loop.&amp;nbsp; The way you have written it, only one row will be read and tested and then the break statement will cause the while loop to be exited (in other words, you are not processing a while loop at all, just one record of the table).&amp;nbsp; I can see why your code now avoids an error or an infinite loop, but that is because it is only considering one record and then stopping.&amp;nbsp; If the code you wrote is actually doing what you want, get rid of the while loop, because it is not being used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To make your code run as a true While loop and process multiple tests where you could actually delete any or all of the files where you encounter matching true conditions in any of your records, you must indent the code as follows.&amp;nbsp; Also, now you must use the Exists test to avoid the possibility of attempting to delete a file multiple times and you can no longer break out of the loop.&amp;nbsp; (The break only works with a single test.&amp;nbsp; Now that you have multiple tests, a break with any of the conditions would cause only the first of the conditions encountered to cause a file deletion, but leave all of the other files untouched even if another record in the feature class would meet the conditon for deleting a different file).&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys, string, os, arcgisscripting
gp = arcgisscripting.create(9.3)

Mooring_Structure = "Mooring_Structure.shp"
P_L = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines"
Clip_Feature = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature\\Clip_Feature.shp"
gp.FeatureClassToFeatureClass_conversion("\\\\Atlas\\data\\geodata\\statelamblands\\moor_struct\\arc", P_L, Mooring_Structure, "")

gp.workspace = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature"
scursor=gp.SearchCursor(Clip_Feature)
row=scursor.Next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'North Coast':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.Exists("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'Murray Inland':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.Exists("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Contour.shp"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Contour.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.Exists("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.GetValue("Region") == 'South Coast':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.Exists("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete_management("C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Lamberts_Projection\\Pts_Lines\\Mooring_Structure.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; row=scursor.Next() # This line must be indented one level to be inside the while loop.&amp;nbsp; If it is not, the while loop never advances the row and becomes infinte.
del scursor&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:27:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186518#M6348</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T09:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186519#M6349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your modified code.&amp;nbsp; I am now using this.&amp;nbsp; I have now added more complexity to the IF statement by utilising 'NOT' condition.&amp;nbsp; That is, instead of evaluation if something is present, it is evaluating if something is absent.&amp;nbsp; This is shown is a subsection of my script below.&amp;nbsp; I am finding the IF statement to be quite useful.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;scursor=gp.SearchCursor(Clip)
row=scursor.Next()
if row.GetValue("Region") &amp;lt;&amp;gt; 'Murray Inland':
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer("Boatmap_Index.shp", "Boatmap_Index_lyr")
del scursor&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:27:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186519#M6349</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2021-12-11T09:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Python if ... then Statement</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186520#M6350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi.&lt;BR /&gt;&lt;BR /&gt;Thanks for your modified code.&amp;nbsp; I am now using this.&amp;nbsp; I have now added more complexity to the IF statement by utilising 'NOT' condition.&amp;nbsp; That is, instead of evaluation if something is present, it is evaluating if something is absent.&amp;nbsp; This is shown is a subsection of my script below.&amp;nbsp; I am finding the IF statement to be quite useful.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;scursor=gp.SearchCursor(Clip)
row=scursor.Next()
if row.GetValue("Region") &amp;lt;&amp;gt; 'Murray Inland':
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer("Boatmap_Index.shp", "Boatmap_Index_lyr")
del scursor&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am glad you found my code useful and I hope it helps you understand how While loops are structured.&amp;nbsp; As far as your new code, you are again testing just one record out of what I assume could be many records.&amp;nbsp; That seems arbitrary to me.&amp;nbsp; What if the first record has a value of "Murray Inland", but the second record does not?&amp;nbsp; Wouldn't you want to create the layer then?&amp;nbsp; Or rather, wouldn't you want to create a layer file and filter out values with "Murray Inland" through a definition query?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since I don't know how you are using this information in your model, I cannot predict exactly what behavior you are looking for.&amp;nbsp; However, normally when looking at multi-record data in combination with conditional requirements, its is rarely a simple matter of looking at one arbitrary record and making a decision based on the information contained in that one record alone.&amp;nbsp; So think this through a little bit more to make sure it really is doing what you want.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:27:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-if-then-statement/m-p/186520#M6350</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T09:27:26Z</dc:date>
    </item>
  </channel>
</rss>

