|
POST
|
Line 8 will always print 1, since you are selecting only one feature ( where OBJECTID_1 = 123 - or some other number). I normally wouldn't use a SearchCursor to select a group of records in this case. I would just use the suggestion from Dan Patterson: arcpy.MakeFeatureLayer_management(fc, 'FcLyr')
arcpy.management.SelectLayerByAttribute('FcLyr', "CLEAR_SELECTION")
result = int(arcpy.GetCount_management('FcLyr').getOutput(0))
print (result)
arcpy.CopyFeatures_management('FcLyr', "C:/Temp/blah/blah.gdb/blah")
... View more
08-24-2020
11:27 AM
|
1
|
0
|
5017
|
|
POST
|
I avoid using the "altered" property. Once a parameter has been changed, altered always checks true. In addition, the script tool seems to create new instances of the tool validator every time a parameter is checked. So I check the values of the parameters and take the appropriate actions. Here is my suggestion for your validator code: import arcpy
class ToolValidator(object):
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup arcpy and the list of tool parameters."""
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
return
def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
options = ['Option 1', 'Option 2', 'Option 3']
filters = [['1','2','3','4'], ['a', 'b', 'c'], ['dr', 'bht', 'cjjjyy']]
if self.params[0].value == options[2]:
if self.params[1].filter.list != filters[2]:
self.params[1].filter.list = filters[2] # update filter.list
self.params[1].values = filters[2] # select all
# self.params[1].values = None # clear all selections
elif self.params[0].value == options[1]:
if self.params[1].filter.list != filters[1]:
self.params[1].filter.list = filters[1] # update filter.list
self.params[1].values = filters[1] # select all
# self.params[1].values = None # clear all selections
else:
self.params[0].value = options[0] # set to default value
if self.params[1].filter.list != filters[0]:
self.params[1].filter.list = filters[0] # update filter.list
self.params[1].values = filters[0] # select all
# self.params[1].values = None # clear all selections
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return EDIT: I updated my code above after discovering that a user could edit the text for "Option 1", etc., and enter an "Option 4". The code now will set "Option 1" as the default. In your code, you were changing the filter list and selecting all values to match the "Option n" setting even if the list in use already matched the option. That was causing select/unselect buttons to freeze. As an alternative to using the "altered" property, you may wish to use the "hasBeenValidated" property. When a parameter has been checked by updateParameters, this value is set to true. When the user changes the parameter, the value is set to false. A code example: if self.params[0].value and not self.params[0].hasBeenValidated: Hope this helps.
... View more
08-20-2020
06:15 PM
|
2
|
0
|
2431
|
|
POST
|
The error message is occurring with the line: arcpy.SelectLayerByAttribute_management('FcLyr', "NEW_SELECTION", row[0]) #"OBJECTID = {}".format(row[0]) Your comment at the end was the right idea, you just needed to make row[0] a string to work in the where clause. And row[0] by itself is not a valid where clause. arcpy.SelectLayerByAttribute_management('FcLyr', "NEW_SELECTION", "OBJECTID = {}".format(str(row[0])))
... View more
08-20-2020
03:49 PM
|
0
|
2
|
5017
|
|
POST
|
This may answer one of your questions: How To: Update the maximum record count for feature services in ArcGIS Online
... View more
08-20-2020
11:41 AM
|
0
|
0
|
1994
|
|
POST
|
This thread is similar, but points instead of lines. It may be helpful: Move point geometry to other location based on common ID.
... View more
08-20-2020
10:23 AM
|
0
|
0
|
1174
|
|
POST
|
I had also noticed that the API for Python's geometry_filter was a bit more limited than the REST API query which allows you to enter an x-y point and specify a distance. Perhaps this will be added to the Python API at some future date.
... View more
08-20-2020
10:18 AM
|
1
|
0
|
3433
|
|
POST
|
Have you tried the geometry_filter argument in the FeatureLayer.query. geometry_filter Optional from arcgis.geometry.filter. Allows for the information to be filtered on spatial relationship with another geometry. See the usage example for intersects for a coding example on this help page: arcgis.geometry.filters module
... View more
08-19-2020
07:03 PM
|
1
|
2
|
3433
|
|
POST
|
There is this support page: Error: Failed to update domain: ERROR: Domain is used beyond the scope of the service.
... View more
08-19-2020
11:37 AM
|
0
|
0
|
1736
|
|
POST
|
I would use ArcCatalog to verify that the path and name of the attachment table is correct. My initial guess is that the attachment table's name is actually '...\Observations__ATTACH' (with 2 underscore characters). It appears that you are using only one underscore between Observations and ATTACH.
... View more
08-13-2020
04:26 PM
|
0
|
0
|
632
|
|
POST
|
Try changing the last line from Try.save(r"H:\Stak1108\Fresh\Try")
Have it use the locations specified by "save_raster" with this: Try.save(save_raster)
... View more
08-13-2020
10:26 AM
|
2
|
1
|
4297
|
|
POST
|
Perhaps a folder input field and a save raster (string) input field. A simple demo script: import arcpy, os
folder = arcpy.GetParameterAsText(0) # Input, Data Type 'Folder'
raster = arcpy.GetParameterAsText(1) # Input, Data Type 'String'
arcpy.AddMessage("Folder: {}".format(folder))
arcpy.AddMessage("Raster: {}".format(raster))
# save location
save_raster = os.path.join(folder, raster)
arcpy.AddMessage("Save Location: {}".format(save_raster))
'''
Output:
Executing: GetFolder C:\Temp\Rasters Stak123
Start Time: Wed Aug 12 19:14:29 2020
Running script GetFolder...
Folder: C:\Temp\Rasters
Raster: Stak123
Save Location: C:\Temp\Rasters\Stak123
Completed script GetFolder...
Succeeded at Wed Aug 12 19:14:29 2020 (Elapsed Time: 0.00 seconds)
'''
... View more
08-12-2020
08:16 PM
|
2
|
3
|
4297
|
|
POST
|
A couple of suggestions: First, delete lines 10-13, and just use the variable "Input_Layer" as the in_table for all the FieldCalculator calls. Second, the code block should be able to all your calculations in one pass. I'm not exactly sure of your table layout, but perhaps something like: # CALfield = 'xyz' # does this come from another field?
rec = 0
def autoIncrement(CALfield):
global rec
pStart = 1
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return CALfield + str(rec).zfill(6)
# xyz000001 If the calculation is more complicated, then you may wish to use an UpdateCursor. Regarding the specific error, "IDPK_Field is not defined", you may need to check if the user correctly selected an existing field in the "Input_Layer". The tool validator code section can be used to assist in this operation. Since you want to update the IDPK_Field, this is a text field of sufficient length, correct?
... View more
08-12-2020
05:17 PM
|
2
|
3
|
2384
|
|
POST
|
Look at Michael Kelly's script in this thread. Is this similar to what you want to do? Or do you want to click on a point feature and have the link provided?
... View more
08-12-2020
09:04 AM
|
2
|
1
|
1666
|
|
POST
|
Try changing the direction to input. The folder location is provided by the user, as input. It is not generated by the script, which would be output.
... View more
08-12-2020
08:56 AM
|
2
|
1
|
4297
|
|
POST
|
Perhaps something like this would give you an idea. It is using the OBJECTID; just substitute your tag number field in lines 1 and 2: value = arcpy.da.SearchCursor(feature, ["OBJECTID"],
sql_clause = (None, 'ORDER BY OBJECTID DESC')
).next()[0]
print value
# 19
print value + 1
# 20 If the tag numbers are spread across several features - that is number 1, 3, 4, etc. can be in one feature, and 2, 5 are in another - you may need to use a table or text file to store the last number used. Then read that table/file, issue tag numbers, then update the table/file with the last used number.
... View more
08-05-2020
01:16 PM
|
0
|
0
|
1865
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2016 02:23 PM | |
| 1 | 09-09-2017 08:27 PM | |
| 2 | 08-20-2020 06:15 PM | |
| 1 | 10-21-2021 09:15 PM | |
| 1 | 07-19-2018 12:33 PM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
07:13 PM
|