2

I have a script tool that runs after values from multivalue box are selected.

enter image description here

The code is okay and runs withou any mistakes. But is it possible to make a kind of exception for selection of fields GRAPH and ADVANCED_GRAPH? Because if I run script with two of these boxes activated I get lots of unnecessary data in TOC.

I tried something like this:

all_selected = arcpy.GetParameterAsText(0) 
selected = all_selected.split(";") 
arcpy.AddMessage("Working...")

for s in selected:
    if s == "GRAPH;ADVANCED_GRAPH":
    arcpy.AddMessage("ERROR")

and this

all_selected = arcpy.GetParameterAsText(0) 
selected = all_selected.split(";") 
arcpy.AddMessage("Working...")

for s in selected:
    if s == "GRAPH" and if s == "ADVANCED_GRAPH":
    arcpy.AddMessage("ERROR")

Both methods don't work.

5

This is how your script should look like:

all_selected = arcpy.GetParameterAsText(0)
selected = all_selected.split(";")
arcpy.AddMessage("Working...")

if "GRAPH" in selected and "ADVANCED_GRAPH" in selected:
    arcpy.AddMessage("ERROR")

...
|improve this answer|||||
  • Thanks, that works, also after arcpy.AddMessage("ERROR") I put quit() to stop it working comletely. – Pavel Pereverzev Dec 14 '16 at 9:17
2

I might not be knowledgeable about gis and this is not a complete answer. However it is too long for a comment and for the sake of completeness, I felt the need to add the causes why your trials didn't work:

In the first one, it would work if you did:

if all_selected=="GRAPH;ADVANCED_GRAPH":

but it would fail for the case when all three of them are selected.

In the second one, there is a logic error. If you want to do it via looping, you need to save the state in an outside variable to make it persist through the iteration.

Also:

if s == "GRAPH" and if s == "ADVANCED_GRAPH":

is always false since s cannot be both at the same time.

Also, you can always make the script ignore one command while both are selected.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.