|
POST
|
After making a copy and making a few changes did you run the makeaddin.py script? If you did, could you provide a few more details about the copy/update/install process you used? From Essential Python add-in concepts: The makeaddin.py Python file is a utility script created by Python Add-In Wizard and is used to package the files and folders within the project folder into the compressed add-in file. Double-click this file to create the add-in file. Each time you make changes to the add-in, you must run this script to repackage the add-in file with the latest updates.
... View more
12-07-2018
09:21 PM
|
0
|
1
|
1950
|
|
POST
|
One possibility is to examine the font size property and make it a bit smaller. You might also be able to tweak the height and width properties. See: TextElement
... View more
12-07-2018
12:26 PM
|
1
|
1
|
2954
|
|
POST
|
You can use the REST API to read the feature layer's JSON. You can find the domain information listed in the fields section. For AGOL I have used this code (with modification, it may also work with Portal). It returns a field's domain in an ordered dictionary. From there, you can get the domain's name, type and the name/code pairing. Hope this helps. import urllib
import urllib2
import json
import collections
# Credentials and feature service information
username = <username>
password = <password>
services = [ "FeatureLayerName" ] # service you are interested in
URL = "https://services.arcgis.com/<abcxyz>/arcgis/rest/services/" # modify as needed
# obtain a token
referer = "http://www.arcgis.com/"
query_dict = { 'username': username, 'password': password, 'referer': referer }
query_string = urllib.urlencode(query_dict)
url = "https://www.arcgis.com/sharing/rest/generateToken"
token = json.loads(urllib.urlopen(url + "?f=json", query_string).read())
if "token" not in token:
print(token['error'])
sys.exit(1)
query_dict = { "f": "json", "token": token['token'] }
# display json data
for service in services:
# print service + " - ",
fsURL = URL + service + "/FeatureServer/0" # assumes first layer, may need to adjust
jsonResponse = urllib.urlopen(fsURL, urllib.urlencode(query_dict))
jsonOutput = json.loads(jsonResponse.read(),
object_pairs_hook=collections.OrderedDict)[u'fields']
for field in jsonOutput:
if field["domain"] is not None:
print field["domain"]
EDIT - Also, when you query a feature with the REST API, the returned JSON includes a fields section with a features (attributes) section. You just need to process the fields section for domains and then process the features/attributes.
... View more
12-07-2018
12:23 PM
|
0
|
1
|
1713
|
|
POST
|
The Rectangle Text (in the Drawing toolset) requires a carriage return/line feed pair - at least with Windows. The text box created with Insert>>Text, only needs a newline but will work with a carriage return/line feed. So, you just need to insert a \r (carriage return) in front of the \n (newline / line feed). Here's some sample code. It may be best to remove carriage returns and split on newlines as there may not always be a carriage return. for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
elm.text = elm.text.replace('\n','\r\n')
# some options in splitting/joining
txtList = elm.text.split('\r\n') # split on CR/LF pair
txtList = (elm.text.replace('\r','')).split('\n') # remove CR and split on newline
elm.text = '\r\n'.join(txtList) # join with CR/LF pair
... View more
12-06-2018
04:12 PM
|
1
|
3
|
2954
|
|
POST
|
It appears the text box was created with the Drawing toolset and is "Rectangle Text" as opposed to just Insert >> Text. I'm not sure if all its properties can be accessed via python, which I believe is part of your goal. If you resize the text box in an open map, does the text come back into alignment? Also, if you paste a new version of the text with valid new lines (or just retype the text in the box) then does it come back into alignment? The idea would be to check is box size is an issue, and if line breaks are an issue. It also looks like the text may be full justified, as to left or right justified, or centered. As I haven't experimented much with rectangle text, it might be possible to capture enough properties to do some conversion. When I get some time, I'll do some experiments. In the meantime, some documentation that may help: Adding text that flows within a graphic
... View more
12-06-2018
12:23 PM
|
1
|
1
|
2954
|
|
POST
|
Just curious, what version of ArcMap are you using? I notice your properties box has a few more tabs: Columns and Margins, Area, and Frame.
... View more
12-06-2018
09:46 AM
|
0
|
1
|
1860
|
|
POST
|
I noticed a couple of utilities in the ArcGIS directory that may help if a map file has become corrupted. I would save a backup copy first. Using the MXD Doctor utility and Using the Document Defragmenter utility
... View more
12-05-2018
03:24 PM
|
1
|
1
|
1860
|
|
POST
|
You are on the right track to add the new line character in the print date line of your code. It appears that other new lines are missing in the text block which is probably why things are a bit jumbled when displayed. You can do a couple of things: compose the text as a long line with newlines included (see line 9 below) or join shorter lines together with the new line character (lines 1-7). Hope this helps. >>> txtBlock = [
'U.S. House of Representatives',
'Prepared by the Will County GIS Division',
'Print date: <dyn type=\"date\" format=\"\"/>',
'302 N. Chicago St. Joliet, Il 60432'
]
>>> newTxt = "\n".join(txtBlock)
>>> newTxt
'U.S. House of Representatives\nPrepared by the Will County GIS Division\nPrint date: <dyn type="date" format=""/>\n302 N. Chicago St. Joliet, Il 60432'
>>> print newTxt
U.S. House of Representatives
Prepared by the Will County GIS Division
Print date: <dyn type="date" format=""/>
302 N. Chicago St. Joliet, Il 60432
>>>
... View more
12-05-2018
09:26 AM
|
1
|
6
|
2729
|
|
POST
|
The code works with a shapefile, but does not work for me with a personal geodatabase. Can you explain "does not work" a bit more. Are you getting an error message; if so, what? Are you working in the Python window in ArcMap, or as a stand-alone script? The code appears to work with a file geodatabase. I was successful in selecting a random group of points in a feature layer. If I understand what you want to do, it seems that line 14 in your code could be an update cursor that uses the "sql" where clause to update a field.
... View more
12-04-2018
07:28 PM
|
0
|
0
|
4553
|
|
POST
|
When you look at the text box's properties, are there changes to the font, font size or centering?
... View more
12-04-2018
02:13 PM
|
0
|
8
|
2729
|
|
POST
|
Parse returns a list of tuples with an address component and a label in each tuple. Tag returns an ordered dictionary and an address type inside a tuple. The documentation says the tag method tries to be a bit smarter - doing some merging, removing comas, etc. Since tag returns a dictionary it is probably easier to work with. The parse method will return both apartment numbers in the bad address in its tuple; the tag method will generate an exception. # Parse
adr = usaddress.parse("5318 S 86 CT APT 3 APT 412, OMAHA, NE 68137")
print adr
AddressNumber = adr[[x for x, y in enumerate(adr) if y[1] == 'AddressNumber'][0]][0]
StreetName = adr[[x for x, y in enumerate(adr) if y[1] == 'StreetName'][0]][0]
StreetNamePostType = adr[[x for x, y in enumerate(adr) if y[1] == 'StreetNamePostType'][0]][0]
print AddressNumber, StreetName, StreetNamePostType
# Tag
adr = usaddress.tag('123 Main St. Suite 100 Chicago, IL')[0] #ordered dictionary inside tuple
print adr
print adr.get("AddressNumber", "") # return address number or empty string
print adr["AddressNumber"] # return address number or key error exception
# Additional error processing
def some_special_instructions(a, b):
d = {}
print "Bad address: {}".format(b)
for row in a:
if row[1] not in d.keys():
d[row[1]] = 1
else:
d[row[1]] += 1
for k, v in d.items():
if v > 1:
print " Repeated Label: {} ({} times)".format(k,v)
try:
tagged_address, address_type = usaddress.tag("5318 S 86 CT APT 3 APT 412, OMAHA, NE 68137")
except usaddress.RepeatedLabelError as e :
some_special_instructions(e.parsed_string, e.original_string)
... View more
11-29-2018
08:48 PM
|
2
|
1
|
3397
|
|
POST
|
Need to figure out why it's giving multiple returns now... In the exception block of your code you are inserting the row once for each digit in the oid: oid = 310 # object id of address causing error
for row in (str(oid)):
print row # this is your insert line
# prints
3
1
0
## try this
except Exception:
cursor1 = arcpy.da.InsertCursor(outErrors, fields)
cursor1.insertRow([addr, addrNum, stNm, zip, oid])
# since this is an insert, oid is probably ignored
# if you want to save the old oid, you will need to use
# a field other than OID@ in the fields list for this value
arcpy.AddMessage("Error with record: {}".format(oid))
arcpy.AddMessage("Bad Input Address = : {}".format(addr))
... View more
11-28-2018
08:39 PM
|
2
|
6
|
4234
|
|
POST
|
There are a couple of ways that you can go. If all the date text contains the address info, you could replace the entire contents with the similar contents that include dynamic text for the date. If the print date line is separated by new line codes \n, you can split your old text, replace the part with the print date and rejoin the text. It appears that your text might follow this pattern. If so, you can try something like this: import arcpy, glob, os
path = r"C:\Directory\with\mxds"
os.chdir(path)
for file in glob.glob("*.mxd"):
print "Processing: {}".format(file)
mxd = arcpy.mapping.MapDocument(file)
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
if ' DATE' in elm.text.upper():
txt = elm.text.split('\n')
for i, t in enumerate(txt):
if ' DATE' in t.upper():
# txt = "Print date: <dyn type=\"date\" format=\"\"/>"
# format date with periods, no leading zero in month
txt[i] = "Print date: <dyn type=\"date\" format=\"M.dd.yyyy\"/>"
elm.text = '\n'.join(txt)
elm.name = 'DateBox'
print elm.text, elm.name
mxd.save()
del mxd If the date text that you want replaced is on the same line with other text ( such as: Print Date: 11/28/2018 By: JP ) then you may need to consider an alternative like regular expressions if a pattern in the text cannot be found. There is a discussion on stackoverflow ( Extracting date from a string in Python ) that would be of interest if you need another option.
... View more
11-28-2018
07:03 PM
|
1
|
10
|
7120
|
|
POST
|
these did work but they replaced everything in the text box with "Print date: 11/28/2018" The map will display today's date using the dynamic text format, however if you look at the properties of the text box, you should see the newdate formula ( Print date: <dyn type="date" format=""/> ) as the text value. Is this not the case?
... View more
11-28-2018
12:09 PM
|
0
|
0
|
2729
|
|
POST
|
Actually, my previous look was too quick. At line 13 in your latest code, you are starting to loop through the text elements in your map. You need to look at the text of each element, that is elm.text. I suspect that you do not want to compare the text to oldText which doesn't change - then every text element would be changed. You mentioned earlier that you had some variations in the text ('Print Date', 'Print date', 'Plot date', etc.). You may want to just use the upper case 'DATE' for comparison, possibly with a space ' DATE' if one will always be there. for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if "PRINT DATE" in elm.text.upper(): #check text in elm
elm.text = newdate # change to dynamic date
# if you want to name the text box as 'PrintDate'
elm.name = 'PrintDate'
print "+++date changed+++" Hope this helps.
... View more
11-28-2018
09:38 AM
|
1
|
14
|
2729
|
| 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
|