POST
|
Hi Matt, Here's the code I ended up using to get around this- I basically set it so that a user had to select between 1 - ### features to run the script. This way, if a user does not select between 1 and ##(say 25) , the script will attempt to run on the entire data set, which will then throw the error message in Line 12 featureLayer = arcpy.GetParameter(0) #this line respects the selection
listA =[]
##Add selected features to listA as needed
if len(listA) in range (1,26): #this is the line that ensures something gets selected as long as the dataset is more than 25 features
with arcpy.da.UpdateCursor([insertlayerhere], ([comma separated fields here])) as uc:
for row in uc:
uc.updateRow(row)
msg1= "OBJECTID(s) {0} will be InsertActionHere".format(listA)
else:
msg1="Please select between 1 and 25 valid features."
#pass message 1
arcpy.SetParameterAsText(1, msg1)
""""
instead of line 6 / passing everything into a list the following code also works:
features = int(arcpy.GetCount_management(featureLayer).getOutput(0))
""" Hope this makes sense, let me know if not, I'd be happy to discuss further!
... View more
05-01-2018
03:59 PM
|
0
|
0
|
606
|
POST
|
Hi Ernestocd I achieved this by creating a python script from desktop and publishing as a Geoprocessing service that can then be served up in the geoprocessing widget. Your script should contain an output that has an arcpy.AddMessage() and arcpy.SetParameterAsText() . The set parameter as text will be the thing that passes information as an output. Here's a small snippet of what this looks like: In the properties of the script tool, set your parameter properties to be Type: Derived & Direction: Output (this makes sure the message you put in for SetParameterAsText() is an output) Additionally, when you are publishing your service on the Parameters tab of the Service Editor box, set the message level to Info Hope this helps! Feel free to reach out if you get stuck
... View more
04-02-2018
08:21 AM
|
6
|
3
|
1921
|
POST
|
Hello Chris, I ended up using a work around that identified a range of features a user could select and run the function for.My database had more than 20000 features, so I set that a selection range had to be between 1 & 200, If a user did not select anything, it would read it as if all 20000 features were selected & so the function would not run. Not the most ideal solution, but a work around nonetheless. I'd be happy to share this part of the code logic with you if it would help.
... View more
03-02-2018
08:03 AM
|
0
|
2
|
606
|
POST
|
Hey Doug, do you have an example of what your UI actually looks like that runs this? Any chance you can share some of the code you used for the GP tool? And is it a PDF by PDF basis or does it work to create multiple maps?
... View more
12-13-2017
03:35 PM
|
0
|
2
|
2191
|
POST
|
Thank you Juan, this is really helpful! Great recommendation!
... View more
12-07-2017
11:24 AM
|
0
|
0
|
628
|
POST
|
I am looking for a way to create something like the print PLUS widget that also will regard wither a filter or what is in the frame of the print and make a calculation based on the data visible and put the output of the calculation on the print out. For example, we have fields of fruit. If our map is zoomed to only show an apple and an orange grove, I would like my printed map to calculate (from a sum of acreage column in the data) and show that I have 12 acres of orange trees and 6 acres of apple trees. Robert Scheitlin, GISP would you be interested in doing some side work? It's a fast approaching deadline (looking to get this in before 2018)
... View more
11-28-2017
11:45 AM
|
0
|
4
|
984
|
POST
|
xander_bakker , yes. It should detect the selection made in the WAB by the current user.
... View more
11-20-2017
10:24 AM
|
0
|
2
|
1611
|
POST
|
Hi Xander, To clarify- I am attempting to use this python code as a geoprocessing tool in AGOL webapp builder. I test from desktop before publishing as a GP service, but ultimately the script needs to work as a GP service from the geoprocessing widget in WAB.
... View more
11-16-2017
09:40 AM
|
0
|
4
|
1611
|
POST
|
Sure thing, do you have an email I can send to directly?
... View more
11-07-2017
02:57 PM
|
0
|
5
|
1921
|
POST
|
Thanks Dan, the issue with GetCount_management is that if I have nothing selected, it sees all the records in the layer so it retruns message 2 (too many features selected) instead of message1 (no features selected)
... View more
11-07-2017
12:11 PM
|
0
|
1
|
1611
|
POST
|
Ryan, I found a work around to help with this if you are doing it in an out of the box GP widget. . Let me know if you are still needing help with this
... View more
11-07-2017
12:09 PM
|
0
|
7
|
2225
|
POST
|
I am currently working on a script that reads the number of features selected in a layer and returns a message or does a function based on how many records are selected. If 0 are selected: it tells the user to "make a selection" If >10, it tells users "too many features selected, must be less than 10" If they select between 1-10 features, it runs the rest of the function. I have the following logic: features = int(arcpy.GetCount_management (featureLayer).getOutput(0)) if features<1: arcpy.addmessage(msg1) elif features>10: arcpy.addmessage(msg2) else: function proceeds.... The issue with this logic is that if no features are selected (if features<1:) it reads it as the count of the entire feature class and so returns msg2. I tried instead to use the logic of desc = arcpy.Describe (Featureclass) if desc.FIDset ==' ': arcpy.addmessage (msg1) This second logic works in ArcGIS desktop, but will not work in AGOL if I publish as a Geoprocessing service. Can anyone think of any workarounds that will recognize if 0 records are selected?
... View more
11-07-2017
12:06 PM
|
0
|
14
|
3211
|
POST
|
Grant, the solution you propose to adding a message in the Geoprocessing tool of WAB, will this work in the out of the box version of WAB or does it need to be a custom widget in web app developer?
... View more
10-30-2017
04:04 PM
|
1
|
2
|
694
|
Title | Kudos | Posted |
---|---|---|
1 | 04-10-2020 12:14 PM | |
2 | 11-18-2021 10:11 AM | |
1 | 12-30-2020 10:39 AM | |
1 | 05-21-2018 10:00 AM | |
1 | 06-11-2020 10:52 AM |
Online Status |
Offline
|
Date Last Visited |
05-21-2024
11:35 PM
|