<?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: for-loop doesn't work with parameters in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422601#M33219</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Martin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you please post your script?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 May 2012 17:25:08 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2012-05-09T17:25:08Z</dc:date>
    <item>
      <title>for-loop doesn't work with parameters</title>
      <link>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422600#M33218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi folks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope I can describe my problem in english, it's hard enough for me in german...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wrote a Python-script which runs different tools for each row of the attribute-table of an layer by using a SearchCursor and a "for row in rows"-loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This worked great so far.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then I rewrote the script, so that not only I can use it (with my set layers), but anyone else too. Therefore I set parameters for the script in the toolbox, so that anyone who wants to use the script can do this with his own layers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now here is the problem:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It works great, but only for the first row. The for-loop doesn't work anymore, it runs the different tools only one time and is finished after that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you please tell me, how i can set the properties of the script, so it can run the for-loop, if I use the parameters?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I searched for long in the online-help, but I found nothing that could help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please excuse my bad spilling, if i wrote a bit strange.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you and greetings,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 17:20:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422600#M33218</guid>
      <dc:creator>MartinBurger</dc:creator>
      <dc:date>2012-05-09T17:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: for-loop doesn't work with parameters</title>
      <link>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422601#M33219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Martin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you please post your script?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 17:25:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422601#M33219</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2012-05-09T17:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: for-loop doesn't work with parameters</title>
      <link>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422602#M33220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here it is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Check out any necessary licenses (lädt benötigte Lizenzen)
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("spatial")

# Local variables: (definiert Variablen)

jea1__2_ = arcpy.GetParameterAsText(0)
finras = arcpy.GetParameterAsText(1)
jea1_1 = arcpy.GetParameterAsText(2)
jea1 = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Speicherort_Sichtfeld = arcpy.GetParameterAsText(3)
Speicherort_Reclassify = arcpy.GetParameterAsText(4)
Speicherort_Raster_zu_Polygon = arcpy.GetParameterAsText(5)
Speicherort_Gefaehrdung = arcpy.GetParameterAsText(6)

value =&amp;nbsp; 0


# Definieren des Search Corsor

rows = arcpy.SearchCursor(jea1, "", "", "", "FID A")

# Beginnt mit for-Schleife für row in rows

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Local variables:


&amp;nbsp;&amp;nbsp;&amp;nbsp; # value wird aus den Werten der verschiedenen Spalten der jea1-Attributtabelle zusammengesetzt 
&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row.getValue("Typ") + str(row.getValue("Abteilung")) + "_" + str(row.getValue("lfdNr_Abt"))

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Speicherorte und -namen der verschiedenen Berechnungen werden definiert
&amp;nbsp;&amp;nbsp;&amp;nbsp; sichtfeld = Speicherort_Sichtfeld + "\\" + "sife_" + value
&amp;nbsp;&amp;nbsp;&amp;nbsp; sf_rcl = Speicherort_Reclassify + "\\" + "sf_" + value + "_rcl"
&amp;nbsp;&amp;nbsp;&amp;nbsp; poly_shp = Speicherort_Raster_zu_Polygon + "\\" + "poly_" + value + ".shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; gefaehrdet_shp = Speicherort_Gefaehrdung + "\\" + "gefdt_" + value + ".shp"



&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Layer nach Attributen auswählen
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(jea1__2_, "NEW_SELECTION", "\"FID\" = " + str(row.getValue("FID")))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Sichtfeld
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Viewshed_3d(finras, jea1, sichtfeld, "1", "FLAT_EARTH", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Reclassify
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.Reclassify_sa(sichtfeld, "VALUE", "0 NODATA;1 1", sf_rcl, "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Raster zu Polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RasterToPolygon_conversion(sf_rcl, poly_shp, "SIMPLIFY", "VALUE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: �?berschneiden (Intersect)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Intersect_analysis( [poly_shp, jea1_1] , gefaehrdet_shp, "ALL", "", "INPUT")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The "arcpy.GetParameterAsText()"-commands import the layers I specify in the parameters, which where set by me in the script-properties. I hope I explained it sufficiently.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:05:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422602#M33220</guid>
      <dc:creator>MartinBurger</dc:creator>
      <dc:date>2021-12-11T19:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: for-loop doesn't work with parameters</title>
      <link>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422603#M33221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Martin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it looks like you are not incrementing your parameters properly. You have already indexed your first parameter as (0) and then you did it again for 'Jea1' Try incrementing it after your last parameter so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;jea1 = arcpy.GetParameterAsText(7)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would suggest reordering your indexed parameters so that it is easier to read as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 18:10:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422603#M33221</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2012-05-09T18:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: for-loop doesn't work with parameters</title>
      <link>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422604#M33222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ok, I changed that. I didn't need the "jea1__2_", so I erased it from the script. The code is now:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Check out any necessary licenses (lädt benötigte Lizenzen)
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("spatial")

# Local variables: (definiert Variablen)

jea1 = arcpy.GetParameterAsText(0)
finras = arcpy.GetParameterAsText(1)
jea1_1 = arcpy.GetParameterAsText(2)

&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Speicherort_Sichtfeld = arcpy.GetParameterAsText(3)
Speicherort_Reclassify = arcpy.GetParameterAsText(4)
Speicherort_Raster_zu_Polygon = arcpy.GetParameterAsText(5)
Speicherort_Gefaehrdung = arcpy.GetParameterAsText(6)

value =&amp;nbsp; 0


# Definieren des Search Corsor

rows = arcpy.SearchCursor(jea1, "", "", "", "FID A")

# Beginnt mit for-Schleife für row in rows

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Local variables:


&amp;nbsp;&amp;nbsp;&amp;nbsp; # value wird aus den Werten der verschiedenen Spalten der jea1-Attributtabelle zusammengesetzt 
&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row.getValue("Typ") + str(row.getValue("Abteilung")) + "_" + str(row.getValue("lfdNr_Abt"))

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Speicherorte und -namen der verschiedenen Berechnungen werden definiert
&amp;nbsp;&amp;nbsp;&amp;nbsp; sichtfeld = Speicherort_Sichtfeld + "\\" + "sife_" + value
&amp;nbsp;&amp;nbsp;&amp;nbsp; sf_rcl = Speicherort_Reclassify + "\\" + "sf_" + value + "_rcl"
&amp;nbsp;&amp;nbsp;&amp;nbsp; poly_shp = Speicherort_Raster_zu_Polygon + "\\" + "poly_" + value + ".shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; gefaehrdet_shp = Speicherort_Gefaehrdung + "\\" + "gefdt_" + value + ".shp"



&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Layer nach Attributen auswählen
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(jea1, "NEW_SELECTION", "\"FID\" = " + str(row.getValue("FID")))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Sichtfeld
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Viewshed_3d(finras, jea1, sichtfeld, "1", "FLAT_EARTH", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Reclassify
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.Reclassify_sa(sichtfeld, "VALUE", "0 NODATA;1 1", sf_rcl, "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Raster zu Polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RasterToPolygon_conversion(sf_rcl, poly_shp, "SIMPLIFY", "VALUE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: �?berschneiden (Intersect)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Intersect_analysis( [poly_shp, jea1_1] , gefaehrdet_shp, "ALL", "", "INPUT")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As before, the different steps work and the results are ok. But it is still the problem, that it only runs once and is finished then.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I ran the script without the parameters defined and just had the pathes of the layers instead of the "GetParameterAsText()" in it, it ran the fore-loop until all rows in the attribute-table where edited.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:05:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422604#M33222</guid>
      <dc:creator>MartinBurger</dc:creator>
      <dc:date>2021-12-11T19:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: for-loop doesn't work with parameters</title>
      <link>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422605#M33223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey guys,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it's pretty embrassing for me, but I've solved my problem and want to tell you, what was wrong:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As I rewrote the script, so that it could be used by setting parameters, I tested it several times, until it was faultless. While I was testing, I didn't notice, that the first row of my "Jea1"-Layer was selected all the time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So when I ran the script again and "jea1" was (I don't know how tosay) imported (?), it only imported the first row of the layer. Due to this fact, the script could only run one time and end then, because in this moment there was only one row which could be edited.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I added a line to the script, which clears any selection, before the for-loop begins. So it doesn't matter, if anyone forgets to clear the selections, before running the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.SelectLayerByAttribute_management(jea1, "CLEAR_SELECTION", "")&lt;/PRE&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Although I think now, how stupid I could be, I'm very happy, that everything works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Greetings Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 12 May 2012 08:49:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/for-loop-doesn-t-work-with-parameters/m-p/422605#M33223</guid>
      <dc:creator>MartinBurger</dc:creator>
      <dc:date>2012-05-12T08:49:58Z</dc:date>
    </item>
  </channel>
</rss>

