|
POST
|
List3 should be in the List2 (or ListLayers) order. It is likely that it would match the Table of Contents order.
... View more
03-19-2019
08:35 PM
|
1
|
9
|
4290
|
|
POST
|
You might try: for layer in layers:
if layer.getSelectionSet() is not None:
print layer.name, len(layer.getSelectionSet())
... View more
03-19-2019
08:22 PM
|
0
|
5
|
3175
|
|
POST
|
As Pavan suggests, you need to use the layer's name property in your comparison. Try: import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = mxd.ActiveDataFrame
List1 = ["September", "October", "November", "December"]
List2 = arcpy.mapping.ListLayers(df) # layers are named September and December
List3 = []
for lyr in List2:
if lyr.name in List1:
List3.append(lyr.name) EDIT: As Joshua Bixby shows in his code example, line 6 in my code should read as below. See: ListLayers. # ListLayers (map_document_or_layer, {wildcard}, {data_frame})
List2 = arcpy.mapping.ListLayers(mxd, data_frame=df)
... View more
03-19-2019
05:56 PM
|
0
|
11
|
4290
|
|
POST
|
Is the 7 digit number always unique? That is, it does not depend on a directory such as "CH01" to make it unique? If so, I would probably create a script that walks through all your jpeg directory and inserts the filename as a key and the path as a value into a dictionary. Then you could use an update cursor to read the field containing the jpeg file name (extracting the file name if necessary) and replace the path with the dictionary value.
... View more
03-19-2019
12:13 PM
|
0
|
5
|
3348
|
|
POST
|
It looks as if you want to join tables, not merge them. See Add Join for more information. You would join on the LABEL field. An alternative to the join is to read the dbf files into dictionaries using a SearchCursor, combining them and saving the results. An example: import arcpy
dbf = r"C:\path\to\dbf\AAA.dbf"
flds = ['LABEL', 'AAA']
dic1 = {r[0]: r[1] for r in arcpy.da.SearchCursor(dbf, flds)}
dbf = r"C:\path\to\dbf\BBB.dbf"
flds = ['LABEL', 'BBB']
dic2 = {r[0]: r[1] for r in arcpy.da.SearchCursor(dbf, flds)}
dbf = r"C:\path\to\dbf\CCC.dbf"
flds = ['LABEL', 'CCC']
dic3 = {r[0]: r[1] for r in arcpy.da.SearchCursor(dbf, flds)}
print "LABEL\tAAA\tBBB\tCCC"
for k, v in dic1.iteritems():
print "{}\t{}\t{}\t{}".format(k, v, dic2 , dic3 )
# would give something like:
'''
LABEL AAA BBB CCC
0 100 200 300
1 101 201 301
2 102 202 302
3 103 203 303
4 104 204 304
'''
... View more
03-18-2019
09:52 PM
|
1
|
6
|
3436
|
|
POST
|
Although I haven't worked with check boxes in a Python toolbox, I would suspect that you would have a little bit more control. I do know that global variables work a little better in the Python toolbox provided they are created in getParameterInfo. See: Python toolbox tool objects do not remember instance variables between function calls? and Using Global Variables in Python Toolbox? From the discussion, I noticed the use of the pythonaddins.MessageBox that can be very useful in debugging a script tool or Python toolbox. import arcpy
import pythonaddins
class ToolValidator(object):
....
def updateParameters(self):
# MessageBox( message, boxtitle)
pythonaddins.MessageBox('Altered:\n{}'.format(self.params[0].altered),'self.params[0]')
pythonaddins.MessageBox('Value:\n{}'.format(self.params[0].value),'self.params[0]') By using the pythonaddins MessageBox I discovered that the .altered and .value property are very similar. The .altered appears to be a Boolean indicating if the parameter has a value (the parameter has been altered from being None to having some value). Once a parameter has a value, it will always test as being .altered = True. If you delete the parameter value, the it will test as false. I have not found a way to set .altered to false after a parameter has been checked/validated. Once you are done with debug/testing, you would want to remove the pythonaddins as the MessageBox is extremely annoying for normal operation of a tool.
... View more
03-18-2019
10:01 AM
|
0
|
0
|
4813
|
|
POST
|
You have a puzzler here. I've always had problems using global variables in the ToolValidator class. In addition, the .altered property doesn't always work as expected (at least for me). The trick seems to be: don't refresh a parameter if a proceeding one hasn't really changed. I think that is the basic problem you're having, and your globals weren't remembering any previous values correctly. Thus, every updateParameters check found a change, and the tool interface seemed as if it was locked up. It was actually being constantly refreshed to its previous state. For my testing, I created a simple script tool with two input variables. The first used a multi-value string input from a value list filter "A;B;C;D" which gave me the check boxes. I used the multi-value "Any value" input to match your "SequenceTheMoveCodes" section. I did not use any globals in the ToolValidator. The operation seemed a bit quirky, but I could alter the order of the items, and delete some. This section would immediately refresh to new values when I deleted all values. Here's the code section from the ToolValidator: def updateParameters(self):
if self.params[0].altered: # a checkbox has changed
if self.params[0].values: # something is checked
if self.params[1].values: # the select section has values
for v in self.params[0].values: # add new values
if v not in self.params[1].values:
self.params[1].values.append(v)
else: # populate select section with checkbox items
self.params[1].values = self.params[0].values
return
As I mentioned, the operation seemed a bit quirky. I am also wondering if there is any value in adding the list of checkboxes when items can be deleted and reordered in the "sequence" section if it is working correctly. So I tested the following code. The first parameter was set to "workspace" so I could select a geodatabase. The second parameter was a "string" which could be populated with a dropdown list of domain names. The final parameter was the multi-value "any value" option to match your "sequence" section. These parameters seem to be the most important of what you are working with. Again, I did not use any global variables. def updateParameters(self):
if self.params[0].altered: # geodatabase parameter has changed
if self.params[0].value: # it has a value
# do checks on params[0] if required - confirm it is geodatabase
# get domain information
domains = arcpy.da.ListDomains(self.params[0].value)
# populate parameter with coded value domain names
self.params[1].filter.list = sorted([d.name for d in domains if d.domainType == "CodedValue"])
if self.params[1].value not in self.params[1].filter.list: # set domain selection if needed
self.params[1].value = self.params[1].filter.list[0]
if self.params[1].altered: # selected domain has changed
if self.params[1].value: # it has a value
domains = arcpy.da.ListDomains(self.params[0].value)
for d in domains: # get the coded values
if d.name == self.params[1].value:
coded_values = d.codedValues
dVals = [val for val, desc in coded_values.items()]
if not self.params[2].values: # the select list has no values in it
self.params[2].values = dVals # insert new values
else: # check the current values
for v in self.params[2].values:
if v not in dVals: # if not in dVals, then domain selection has changed
self.params[2].values = dVals # reset choices
break
return Basically, if a geodatabase and a domain name have been selected, the sequence section of the tool is populated with the codes from the first coded-value domain found. When a domain code is highlighted, the "x" button will remove it from the list. The up and down arrows should move the code in the list. If the domain name is changed, the script checks to see that all values in the sequence area are in the codes used by the newly selected domain. If a value exists that is not in the domain codes, it is assumed the domain name was changed, and the sequence section is refreshed. As noted in the code, I do not check that the workspace is an actual database. Also there is no error processing if the selected database does not have coded value domains. Here's what my test tool interface looks like Hope this helps.
... View more
03-16-2019
06:49 PM
|
2
|
3
|
4813
|
|
POST
|
Could you describe the properties/settings you are using for the "SequenceTheMoveCodes" control?
... View more
03-15-2019
09:32 AM
|
0
|
1
|
4813
|
|
POST
|
The text appearing in the "Value" window doesn't look like well formed JSON. It looks like it is a paste inside a previous paste. If you want "feature" inside the window, it should be in quotes as should "attributes" along with some commas in there. I would also suspect that the Name should be "features" not "updates". I must admit, however, that I am not very familiar with Integromat. To check your JSON, try jsonlint.
... View more
03-14-2019
09:23 PM
|
0
|
1
|
3900
|
|
POST
|
Here's an example of passing the list in an Excel workbook: import arcpy, xlrd
fileName = arcpy.GetParameterAsText(0) # Input, Data Type 'File', File Filter 'xls; xlsx'
arcpy.AddMessage("File Name: {}".format(fileName))
# open workbook
xls = xlrd.open_workbook(fileName)
# get the first worksheet - see xlrd docs for opening .sheet_by_name('name')
sheet = xls.sheet_by_index(0)
num_rows = sheet.nrows - 1
curr_row = 0 # we will skip row 0, assuming that it is a header
while curr_row < num_rows:
curr_row += 1 # advance to next row
pin = sheet.row_values(curr_row)[0] # read first column
arcpy.AddMessage("Processing: {}".format(pin))
# do stuff with pin Results: Executing: PinTest C:\pin_nums.xlsx
Start Time: Thu Mar 14 19:54:44 2019
Running script PinTest...
File Name: C:\pin_nums.xlsx
Processing: PIN0392800001
Processing: PIN0392800002
Processing: PIN0392800003
Processing: PIN0392800004
Processing: PIN0392800005
Processing: PIN0392800006
Processing: PIN0392800007
Processing: PIN0392800008
Processing: PIN0392800009
Processing: PIN0392800010
Completed script PinTest...
Succeeded at Thu Mar 14 19:54:44 2019 (Elapsed Time: 0.03 seconds)
Tool parameter is set as: My test workbook is attached. Hope this helps.
... View more
03-14-2019
08:46 PM
|
1
|
0
|
3983
|
|
POST
|
I would try \" : [
{
"attributes": {
"OBJECTID": 307,
"Comments": "This is a test \"with quotes\""
}
}
]
... View more
03-13-2019
11:52 AM
|
0
|
6
|
3900
|
|
POST
|
I am making an assumption that the 500 parcels are in some kind of a list. I think that you should be able to loop through your list (or a file containing the list) and call your tool. I haven't done any testing, but the idea would be something like: import arcpy
# Load the toolbox and get the tool's parameters, using the tool
# name ( ie. "myToolbox" - not the tool label "My Toolbox" )
arcpy.ImportToolbox(r"C:\Projects\MyToolbox.tbx", "myToolbox")
# read your list file
for item in listFile:
arcpy.NameOfTool_myToolbox(item) # your tool's parameters As an alternative, you might be able to adapt your script tool to use a list file as an input parameter instead of a manual entry. I suppose you could get a lot of duplicate parcels when you work your way through the list. If so, you could add a flag field to your parcel layer and select all parcels within your buffer distance of the flagged parcels.
... View more
03-13-2019
11:38 AM
|
0
|
2
|
3983
|
|
POST
|
You would need to change the dbTable name to one of your tab names: # line 76 and 84 from above -- change from
dbTable = "Domain1"
# to
dbTable = "AccessSts" # a tab name in your workbook that you want to become a table The section of the code above after line 72 sets up the values used in the new_table function. In the example code, it creates 2 tables using 2 tabs in an Excel file. Another way to read lots of tabs into domains without creating tables: import xlrd
import arcpy
from arcpy import env
# name of geodatabase
geoDB = r"C:\Users\Randy\Documents\ArcGIS\PythonScripts\domains\domain_test.gdb"
# name of excel workbook
excelWB = r"C:\Users\Randy\Documents\ArcGIS\PythonScripts\domains\Parks_Domains.xlsx"
# lots of sheets in excel workbook, let's loop through them
xls = xlrd.open_workbook(excelWB, on_demand=True)
tabs = xls.sheet_names() # <- remeber: xlrd sheet_names is a function, not a property
isNum = ['ZipCode'] # list of tabs whose domain code is a number (not a number as text)
for tab in tabs:
print "Processing tab: {}".format(tab)
if tab in isNum: # if tab name is in number list, set type to long integer (or "SHORT")
fldType = "LONG"
else: # otherwise, set it to text
fldType = "TEXT"
print "\tCreating domain"
arcpy.CreateDomain_management(in_workspace= geoDB, # geodatabase
domain_name= tab, # tab name will be the domain name
domain_description= tab, # tab name will be the description
field_type= fldType, # set field type
domain_type= "CODED", # this is a coded value domain
split_policy= "DEFAULT",
merge_policy= "DEFAULT")
print "\tAdding codes and descriptions:"
sheet = xls.sheet_by_name(tab)
num_rows = sheet.nrows - 1
curr_row = 0
while curr_row < num_rows:
curr_row += 1
cd, desc = sheet.row_values(curr_row)
if fldType == "LONG": # if field type is long integer
cd = int(cd) # convert code to integer
print "\t\t{}\t{}".format(cd, desc)
arcpy.AddCodedValueToDomain_management(in_workspace= geoDB,
domain_name= tab, # tab name is the domain name
code= cd,
code_description= desc)
print "Done." This uses a couple of other arcpy functions: Create Domain and Add Coded Value To Domain. The basic flow of the program is to add a domain for every tab in the workbook. It assumes a setup similar to the one in your Excel file. Hope this helps.
... View more
03-12-2019
08:13 PM
|
1
|
0
|
2360
|
|
POST
|
Are you thinking of .index in something like: fields = ['a', 'b']
rows = [[ 5, 10],[20,10]]
for row in rows:
print max(row), fields[row.index(max(row))]
# results:
# 10 b
# 20 a
... View more
03-12-2019
11:48 AM
|
2
|
0
|
1041
|
|
POST
|
Can you provide a little more description of the workflow of your project? Do you want to select a group of parcels by location and link them to a table of owner information? What do you type into your tool for individual and multiple listings?
... View more
03-11-2019
08:00 PM
|
0
|
5
|
3983
|
| 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
|