4

I have a feature layer, and with ModelBuilder (ArcMap 10.8) I'm trying to ensure that the "Iterate Feature Selection" tool is carried out only if there are selected features; if no feature are selected the tool and next steps shoul be skipped. Following the instruction from the Online Help on Using If-Then-Else logic for branching I create a simple python script with two ouputs. If the output indicating that features are selected is true the process should run.

import arcpy
layerName = arcpy.GetParameterAsText(0)
desc = arcpy.Describe(layerName)
if not desc.FIDSet == '':
 arcpy.SetParameterAsText(1,"true")
 arcpy.SetParameterAsText(2,"false")
else:
 arcpy.SetParameterAsText(1,"false")
 arcpy.SetParameterAsText(2,"true")

The issue is when no feature are selected the process still run for every feature in the layer.

Example of model builder with two output options Even when I use 'Iterate Feature Selection' in a separate model, all steps are executed, even if no features are selected

Example of separate model builder for the iteration

How can I resolve?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 23, 2024 at 10:40
1
  • It looks like you are inputting and/or storing three parameters (0, 1, 2) in the first block, but as the selected answer below comments, you haven't chosen to show what you do with them once loaded. Commented Sep 24, 2024 at 19:25

1 Answer 1

5

It's not possible to answer your question as you do not show how you pass in the parameters into your script tool. I suspect the issue is there.

Below is an easier solution using the calculate value tool.

Model

The Calculate value tool is set up as below:

Calculate value tool

For your convenience here is the Code Block:

import arcpy
def hasSelection(layer):
 desc = arcpy.Describe(layer)
 if desc.FIDSet == '':
 b = False
 else:
 b = True
 return b
answered Sep 23, 2024 at 11:04
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.