|
POST
|
Curtis, Thanks. I did that. And to my not-so-experienced eyes I don't see anything odd. Code: txtBlock = [
'Prepared by the Will County GIS Division',
'302 N Chicago St. Joliet, Il 60432',
'T:(815) 774-6343, E:[email protected]',
'Print date: <dyn type=\"date\" format=\"\"/>'
]
newTxt = "\n".join(txtBlock)
# list the mxds of the workspace folder
for mxdname in arcpy.ListFiles("*.mxd"):
print "checking document: {}".format(mxdname)
mxd = arcpy.mapping.MapDocument(ws + "\\" + mxdname)
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if " DATE" in elm.text.upper():
print str(elm.text) + "\n"
print "++++++++++++++below is repr+++++++++++++++++++++"
elm.text = newTxt
print repr(elm.text) Print out: Prepared by the Will County GIS Division
Print Date: 11.2.2018
302 N. Chicago St. Joliet, Il 60432
++++++++++++++below is repr+++++++++++++++++++++
u'Prepared by the Will County GIS Division\n302 N Chicago St. Joliet, Il 60432\nT:(815) 774-6343, E:[email protected]\nPrint date: <dyn type="date" format=""/>' In the map, the text box still goes from this: to this:
... View more
12-06-2018
08:26 AM
|
0
|
0
|
1872
|
|
POST
|
That should work, but neither do? The text is still jumbled in the map document text box. Strange. I then tried on a text box with similar text in a new map document and it worked fine. I'd hate to think the text boxes in these old map documents are corrupt, or something.
... View more
12-05-2018
12:19 PM
|
0
|
5
|
2758
|
|
POST
|
Here's the properties of the text box above. The address line is not where it should be. So, in the script I put another \n after the dynamic date (see below). That didn't change anything. 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[i] = "Print date: <dyn type=\"date\" format=\"\"/>\n"
## format date with periods, no leading zero in month
## txt = "Print date: <dyn type=\"date\" format=\"M.dd.yyyy\"/>"
elm.text = '\n'.join(txt)
elm.name = 'DateBox'
print elm.text, elm.name
... View more
12-05-2018
07:31 AM
|
0
|
7
|
2758
|
|
POST
|
Randy, Thanks for that. I have actually attempted to just replace the whole text box with text including the new dynamic date. It worked, but the text was really hard to read. And using your latest script it's doing the same thing:
... View more
12-04-2018
09:24 AM
|
0
|
9
|
2758
|
|
POST
|
Hi David, Thanks for the reply. It's been ongoing. Our dept. is in the process of switching to a new server that will have an https certificate. I'm anticipating the apps to possibly function once we do. So, I won't know until then.
... View more
12-04-2018
08:21 AM
|
0
|
0
|
1178
|
|
POST
|
I also just tried name the text box, and then changing the text to the "newdate". But this changed the whole text box too. for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if "PRINT DATE" in elm.text.upper():
elm.name = 'PrintDate'
if elm.name == 'PrintDate': #the name of the text element
elm.text = newdate
print "+++date changed+++" from this: to this: "Print date: 11/28/2018" Almost there, but I'm trying to avoid changing the rest of the text in the text box! EDIT: Yes, to answer your latest post, it did exactly what you're pointing out. The problem is that the rest of the text in that same box is gone after the change.
... View more
11-28-2018
12:56 PM
|
0
|
11
|
2758
|
|
POST
|
Randy, Thanks, these did work but they replaced everything in the text box with "Print date: 11/28/2018". newdate = "Print date: <dyn type=\"date\" format=\"\"/>" if " DATE" in elm.text.upper():
elm.text = newdate if "PRINT DATE" in elm.text.upper():
elm.text = newdate
... View more
11-28-2018
11:28 AM
|
0
|
13
|
2758
|
|
POST
|
Randy, Thanks for that. I tried your script verbatim (besides the path variable) and for some reason it won't save (nothing's open, tried saveACopy('test'), unindented, quit python, restarted, etc...). But, as far as the printout goes, it doesn't look like it changed the date because it's showing the same old date. Using yours and Dan's help from before, I put together this script: import arcpy, os
from arcpy import env
arcpy.env.workspace = ws = r"\\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_18\Test Folder"
oldText = "Print Date:9.23.2016"
newdate = "Print date: <dyn type=\"date\" format=\"\"/>" #i want the date text dynamic
# list the mxds of the workspace folder
for mxdname in arcpy.ListFiles("*.mxd"):
print "checking document: {}".format(mxdname)
mxd = arcpy.mapping.MapDocument(ws + "\\" + mxdname)
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if "Print Date" in oldText.upper():
new_fixed = "{}: {}".format(oldText.split(":")[0], newdate)
print "+++date changed+++"
mxd.save()
del mxd
However, it doesn't print the second statement or change the text in the MXD. I'm guessing it might have to do with the contents of the text box? This is the actual text box I've been testing on with all it's contents as it is in the MXD. As I said before this "Print Date..." line will have different content in different MXDs; where I'm eventually headed. Also, I've never named any elements in any of the maps. So, I don't see how I'd use this to access the text.
... View more
11-28-2018
08:43 AM
|
0
|
16
|
4423
|
|
POST
|
Dan, I like that approach. The thing is, "oldText" could be "Print Date:", "Plot Date:", "Plot date", etc... I wasn't the originator of the maps. I've only been updating them. So, with that, could I create a list with all these possibilities? I'm basically wondering how to formulate that.
... View more
11-27-2018
07:37 AM
|
0
|
1
|
4423
|
|
POST
|
Randy, Are you aware of a way to name the text boxes with Arcpy? That's a good idea. Sad thing is I'd have to retroactively do that at this point.
... View more
11-27-2018
06:41 AM
|
0
|
19
|
4423
|
|
POST
|
I'm in 4.9. How can I get the popup to display the title of each field using a Webmap? Right now, when you click the feature in the app the title displays as "Sheet1". The feature layer in the Webmap is actually "Warming Center". In the JS (below) I have the Title set up to display the "FACILITY_NAME" field. But, that's not happening. If I use the Map class instead of a Webmap the title displays in the popup just fine. But, in this case I'd rather user a Webmap. var webmap = new WebMap({
portalItem: {
id: "93b7e42b2ca64790aa2315da5eceaff9"
}
});
/************************************************************
* Set the WebMap instance to the map property in a MapView.
************************************************************/
var view = new MapView({
map: webmap,
container: "viewDiv",
popup: {
dockEnabled: true,
dockOptions: {
// Disables the dock button from the popup
buttonEnabled: false,
// Ignore the default sizes that trigger responsive docking
breakpoint: false,
}
}
});
//Popup template
var template = { // autocasts as new PopupTemplate()
title: "{FACILITY_NAME}",
content: [{
type: "fields",
fieldInfos: [{
fieldName: "FACILITY_TYPE",
label: "Facility Type",
visible: true,
}, {
fieldName: "ADDRESS",
label: "Address",
visible: true,
}, {
fieldName: "WEBSITE",
label: "Website",
visible: true,
}, {
fieldName: "PHONE_NUMBER",
label: "Phone",
visible: true,
}, {
fieldName: "HOURS",
label: "Hours",
visible: true,
}]
}]
};
//Reference the popupTemplate instance in the popupTemplate property of FeatureLayer
var featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/fGsbyIOAuxHnF97m/arcgis/rest/services/Warming_Centers_in_and_around_Will_County_IL/FeatureServer/0?token=TBoytrSjk658s73RVxEixBfWiPa_GI5EYBjyRTwYygOilY6kmMaDiHJla-n8ZvLylgt755Owpi4Pvqxk8hzaAM3vfBBx2ueCuCWfenNdfKFxnSEoTfLCTB4kcJqBR1KHJAje4C9tHfcYHJnH1ciTvKBy38vzit7TGUFfVUkQEgXlmhoN4iut9RMll6meOOaUFSa0yPENiXUOxWClJcXzPSe81jiObK3Ecjv4YirstB6GLYanFZ56cEnR66HRwbmB",
outFields: ["*"],
popupTemplate: template
}); I haven't found any reference or help explaining this. WebMap | API Reference | ArcGIS API for JavaScript 4.9 This sample uses a webmap, but I don't see where they set the Title parameter. ArcGIS API for JavaScript Sandbox
... View more
11-19-2018
09:43 AM
|
0
|
1
|
2229
|
|
POST
|
Robert, Thanks for directing me away from the CSS. Whereas before I created a Map instance, I now created a WebMap. And this seems to have answered my question. /************************************************************
* Creates a new WebMap instance. A WebMap must reference
* a PortalItem ID that represents a WebMap saved to
* arcgis.com or an on-premise portal.
*
* To load a WebMap from an on-premise portal, set the portal
* url with esriConfig.portalUrl.
************************************************************/
var webmap = new WebMap({
portalItem: {
id: "93b7e42b2ca64790aa2315da5eceaff9"
}
});
/************************************************************
* Set the WebMap instance to the map property in a MapView.
************************************************************/
var view = new MapView({
map: webmap,
container: "viewDiv", I had a lot of help from these two examples: Load a basic WebMap | ArcGIS API for JavaScript 4.9 Swap web maps in the same view | ArcGIS API for JavaScript 4.9
... View more
11-16-2018
02:16 PM
|
0
|
0
|
1993
|
|
POST
|
I guess what I was asking was whether it's possible to have two different scales, one for the PC and one for the phone.
... View more
11-14-2018
06:35 AM
|
0
|
2
|
1993
|
|
POST
|
I can't seem to find the element to change the scale. Can it be done in the CSS? I've tried this: @media (max-width: 480px) {
view MapView {
scale: 1300000,
}
... View more
11-13-2018
02:33 PM
|
0
|
4
|
2114
|
|
POST
|
I have a working script that searches for a text element in an MXD and replaces it with new text. I'm using it to update the "print date: mo./day/year". But, this method is sort of limited in that it only finds that exact string. In my map document folder, the dates of these maps differ from each other. So, how can I make the script replace an open-ended string? I've tried: oldText = "Print Date: " and oldText = "Print Date: *" As the script is here, "oldText = Print Date: 9.6.2016" will be replaced with "newText = Print Date: 11/13/2018". But, dates on other maps could be anything. If I could replace the old with dynamic text date that would be even better. arcpy.env.workspace = Workspace = r"path\to\TestFolder"
Output = r"path\to\TestFolder2"
oldText = "Print Date: 9.6.2016"
oldList = oldText.split(', ')
newText = "Print Date: 11/13/2018"
newList = newText.split(', ')
# list the mxds of the workspace folder
for mxdname in arcpy.ListFiles("*.mxd"):
print "checking document: {}".format(mxdname)
# set the variable
mxd = arcpy.mapping.MapDocument(Workspace + "\\" + mxdname)
# replace elements that occur in the map document
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
counter = 0
for text in oldList:
if text in elm.text:
elm.text = elm.text.replace(text, newList[counter])
print '{} changed'.format(elm.text)
counter = counter + 1
else:
counter = counter + 1
for elm in arcpy.mapping.ListLayoutElements(mxd, ""):
counter = 0
for text in oldList:
if text in mxd.title:
mxd.title = elm.text.replace(text, newList[counter])
counter = counter + 1
else:
counter = counter + 1
# move the mxd.saveACopy outside of the if loop so a copy is saved even it does not meet the condition of the if loops
mxd.save() #(os.path.join(Output + "\\" + mxdname))
# do not include this delete statement inside the above loop or it will delete the mxd object inside the loop. Make sure to dedent.
del mxd
... View more
11-13-2018
02:16 PM
|
0
|
28
|
9707
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-25-2026 12:25 PM | |
| 1 | 05-04-2026 08:45 AM | |
| 1 | 04-20-2026 01:20 PM | |
| 1 | 07-24-2025 01:27 PM | |
| 1 | 11-13-2025 08:22 AM |
| Online Status |
Offline
|
| Date Last Visited |
12 hours ago
|