I have a script that with a load of shape files that get diced and spliced so I've tried to put it into a For Loop to do all the repetitive stuff but arcpy.GetParameterAsText() does not seem to work in a For loop
I have the following code sample:
for ii in range(3,9): arcpy.AddMessage(ii) inDataString = arcpy.GetParameterAsText(ii) arcpy.AddMessage(inDataString) arcpy.AddMessage("I've survived") arcpy.AddMessage(arcpy.GetParameterAsText(ii))The first parameters (0, 1, and 2) are global therefore the loop starts at 3. For the first run through it returns
3Q:/WSP_UK/WSP_D/Hertford/#TOOLS/CSB_SWMP_Tool_Dev/SmallTestData/nat_floodzone2_v201502.shpI've survivedQ:\WSP_UK\WSP_D\Hertford\#TOOLS\CSB_SWMP_Tool_Dev\SmallTestData\nat_floodzone2_v201502.shpSo from the above, we can see that it's got the correct number, arcpy.GetParameterAsText(ii) is picking up the correct string and setting the variable properly and the rest of the script runs fine and produces what it is supposed to produce.
When the loop moves on to the next ii which is 4. arcpy.GetParameterAsText(ii) doesn't pick up the string and therefore inDataString is empty and results in the following
4I've survivedTherefore as the For Loop progresses, it throws an error because the input to the next line is empty when it shouldn't be. I've put arcpy.GetParameterAsText(4) in to my script prior to the for loop and it picks it up no problem. Similarly, if I change range(3,9) to range(4,9) it works for the first run through when ii=4 then fails for the second time through the loop where ii=5
I'm lost now as to why this is happening. Any ideas?
أكثر...
I have the following code sample:
for ii in range(3,9): arcpy.AddMessage(ii) inDataString = arcpy.GetParameterAsText(ii) arcpy.AddMessage(inDataString) arcpy.AddMessage("I've survived") arcpy.AddMessage(arcpy.GetParameterAsText(ii))The first parameters (0, 1, and 2) are global therefore the loop starts at 3. For the first run through it returns
3Q:/WSP_UK/WSP_D/Hertford/#TOOLS/CSB_SWMP_Tool_Dev/SmallTestData/nat_floodzone2_v201502.shpI've survivedQ:\WSP_UK\WSP_D\Hertford\#TOOLS\CSB_SWMP_Tool_Dev\SmallTestData\nat_floodzone2_v201502.shpSo from the above, we can see that it's got the correct number, arcpy.GetParameterAsText(ii) is picking up the correct string and setting the variable properly and the rest of the script runs fine and produces what it is supposed to produce.
When the loop moves on to the next ii which is 4. arcpy.GetParameterAsText(ii) doesn't pick up the string and therefore inDataString is empty and results in the following
4I've survivedTherefore as the For Loop progresses, it throws an error because the input to the next line is empty when it shouldn't be. I've put arcpy.GetParameterAsText(4) in to my script prior to the for loop and it picks it up no problem. Similarly, if I change range(3,9) to range(4,9) it works for the first run through when ii=4 then fails for the second time through the loop where ii=5
I'm lost now as to why this is happening. Any ideas?
أكثر...