|
POST
|
Is pageNum actually the name of the field you used as the "Name Field" when you set up your DDP? getPageIDFromName (page_name) Parameter Explanation Data Type page_name A value in the index layer that corresponds to the Name field that was used to set up Data Driven Pages String Many of the Data Driven Pages properties and methods use an internal index value rather than the literal names of the pages used to create the index layer. The index values are automatically generated based on the Name and Sort fields. It may not be obvious which index value represents a specific page. The getPageIDFromName method provides a mechanism for this translation. pageID = mxd.dataDrivenPages.getPageIDFromName("HarborView") mxd.dataDrivenPages.currentPageID = pageID R_ [ATTACH=CONFIG]26820[/ATTACH]
... View more
08-20-2013
07:30 AM
|
0
|
0
|
1250
|
|
POST
|
Well, that definatly gets more complicated, however, if you are using 10.1, here is one way. Open your arcmap document that has the most permeatations. create the symbology you want for the values (if it doesn't exist in that layer/map, you can add value to the list, even if it isn't displayed) Adams 1900 - red Bruce 1985 - blue etc... now, save that as a layer file. in your map document, legend properties, check the box that says "Only show classes that are visible in the current map extent" and save the mxd. Now, with python, after you have your data genereated, us the updateSymbology to apply that layer file to the FC. With the "Only show" box checked, you will only see the values/symbology for feature that show in the current layout extent, so, if a particular permeatation doesn't exist in the map, it won't display it on the legend. Of course, now that I think about it some, ESRI has not given python access to the "only show " legend box, so you would have to manually set that on your layer in all your mxd's. Might be able to utilize a template to set this on all mxd's, would have to look into that a little. I see we can change class values, labels, etc., but I don't see any way to assign a color to a feature using python, other than with a .lyr file. If we could, there might be a way to iterate through all of them and append the classes to a list, then get the unique set, create a dictionary from that and apply it to the layer(s) you want. however, not sure how you would control the colors anyone know if we have access to the "colors" used for unique symbology? In the first example you provide above, that changes the symbology including the DisplayField, which is not really what I want. In the second, that shows some of the Layer properties exposed in arcpy, but I am not sure how to access colors for a Unique_Value map. symbology_only - A Boolean that determines whether or not to update only the layer's symbology, or all other properties as well. If set to True, only the layer's symbology will be updated. R_
... View more
08-19-2013
02:17 PM
|
0
|
0
|
3557
|
|
POST
|
It does not run for me at all. In fact, I set root = r'D:' and it gives me .prj files located several folders deep. In no way can I make it report the mxd's in the listed directory. If I start it out like this it will get the list of mxd's:
arcpy.env.overwriteOutput = True
text_elms = []
the_text_elm = None
start = "D:\\"
for root, dirs, files in os.walk(start):
for mapDoc in files:
if mapDoc.endswith(".mxd"):
print 'Working on ',mapDoc
path = os.path.abspath(os.path.join(root,mapDoc))
mxd = arcpy.mapping.MapDocument(path)
text_elms = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Archit")[0]
the_text_elm = None
the_text_elm = text_elm
have you typed print os.listdir(root) and make sure that it only reports mxd files? as mine crashes trying to set the mxd = somefileotherthan mxd (the first file in my directory) the above code "fixes" that. If you are changing for ALL text elements with name = "Archit", you don't need to iterate through the list In fact, you assign it to text_elms, then try to iterate through that as a list. Can't be done as text_elms is a list of TextElement objects, and is not iterable as is not a list (). Then, in this part, do whatever if's you need, but you have assigned the text element to text_elms variable (not the_text_elm), so that is the one you want to update:
if the_text_elm:
i = the_text_elm.text.find('Archit')
new_text = the_text_elm.text[:i] + 'Historic Resources'
text_elms.text = new_text
mxd.save()
Here is modified code that is working for me, you should be able to extract what you need:
import os
import arcpy
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
# Loop over MXDs
folder = r'H:\myDir'
arcpy.env.workspace = folder
arcpy.env.overwriteOutput = True
for root, dirs, files in os.walk(start):
for mapDoc in files:
if mapDoc.endswith(".mxd"):
print 'Working on ',mapDoc
path = os.path.abspath(os.path.join(root,mapDoc))
mxd = arcpy.mapping.MapDocument(path)
if arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Archit"): # this keeps it from erroring out if the text element "Archit" doesn't exist...
text_elms = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "Archit")[0]
new_text = "test" + ' Historic Resources'
text_elms.text = new_text
mxd.save()
Keep in mind this will walk through all sub-folders as well. Hope this gets you on the right track, R_
... View more
08-19-2013
01:43 PM
|
0
|
0
|
1669
|
|
POST
|
Well, if value A and B are the same in all the maps, the easiest way would be to open ArcMap, load your feature class and symbolize as desired. then, right click on the FC and save as layer file. Then, you can use UpdateLayer in python to update the symbology using the layer file you created http://resources.arcgis.com/en/help/main/10.1/index.html#/UpdateLayer/00s30000003p000000/ . If the values for A and B can differ, you can set up and create the layer file in python http://resources.arcgis.com/en/help/main/10.1/index.html#/Layer/00s300000008000000/ , then use that one to update the layer(s). R_
... View more
08-19-2013
12:32 PM
|
0
|
0
|
3557
|
|
POST
|
Geoff, Originally I was expecting the definition queries of the point layer would control which points were being labelled. I didn't know what the python script would disregard that control. You can set the same definition query in the SQLclause portion of the labelClass if you only want it to label features that are valid in the layer definition query. http://resources.arcgis.com/en/help/main/10.1/index.html#/LabelClass/00s30000002t000000/ R_
... View more
08-19-2013
10:50 AM
|
0
|
0
|
2085
|
|
POST
|
For one, your forward/backward sloping single quotes are invalid to the interpreter. It either errors out or just hangs there unitil I kill it. Once I removed them, the script would run. Then, after I put a mxd.save() in there, the class labels are updated in the mxd. Here is the code that works just fine for me, using your example data: # -*- coding: utf-8 -*- import arcpy, os import arcpy.mapping #Pre-defined ???code:name??? key-value pair code_name={'A':'Apples','B':'Bananas','C':'Cherries'} #Get mxd mxd=arcpy.mapping.MapDocument(r"E:\Test_Symbology\Test_Symbology.mxd") #According mxd&layername ???code:name??? key-value pair to modify lyr.symbology.classLabels def EditLyrSymInfo(mxd,lyrName): lyr = arcpy.mapping.ListLayers(mxd, lyrName)[0] if lyr.symbologyType == "UNIQUE_VALUES": Labels=lyr.symbology.classLabels Values=lyr.symbology.classValues upt_Labels=[] print "Layer Symbology Info to be Edit:",lyrName for value in Values: upt_label=code_name[value] upt_Labels.append(upt_label) print u'Labels:{0}, Values:{1};'.format(upt_label,value) lyr.symbology.classLabels=upt_Labels lyr.symbology.showOtherValues = False arcpy.RefreshActiveView() arcpy.RefreshTOC() mxd.save() def main(): #Print Pre-defined code:name key-value pair print '##Print Pre-defined code:name key-value pair##' for key,value in code_name.iteritems(): print key,value lyrName="PlanPolygonSelectR" #After modify lyr.symbology.classLabels(Labels:Values)key-value pair: print '##After modify lyr.symbology.classLabels(Labels:Values)key-value pair:##' EditLyrSymInfo(mxd,lyrName) if __name__=="__main__": main() R_ Keep in mind, I tested this "outside" of ArcMap with a closed mxd. When I re-open the mxd, the changes are shown as expected. Before Script: [ATTACH=CONFIG]26801[/ATTACH] After Script: [ATTACH=CONFIG]26802[/ATTACH] Just tested inside ArcMap with the python window and mxd = CURRENT. works fine.
... View more
08-19-2013
10:23 AM
|
0
|
0
|
6737
|
|
POST
|
I can't seem to be able to make it work either. Must be related to the table view, as if I join directly to a table, it works as in my previous post. I did notice that if I copyRows to an in_memory table, then join to that it works as expected, just not with the table view. R_
... View more
08-15-2013
04:51 PM
|
1
|
0
|
3274
|
|
POST
|
I thought he had tried changing it to double a few posts back, with no luck. So thought it might be elsewhere. R_
... View more
08-15-2013
07:14 AM
|
0
|
0
|
883
|
|
POST
|
Glad it worked for you. Also, I see you gave me a point with the up arrow, would you might selecting the checkbox as answered also? Will give me credit for it and also mark it answered for people searching similar issues in the future. Thanks, R_
... View more
08-14-2013
06:02 PM
|
0
|
0
|
1462
|
|
POST
|
import arcpy
import os
from arcpy import env
from time import localtime, strftime
# Set workspace
arcpy.env.workspace = r'd:\gis\aerialtracking\output'
ws = arcpy.env.workspace
if str(os.path.exists(ws)) == "False":
os.makedirs(ws)
# Set time variable and print output variable
printtime = strftime("%Y%m%d_%H%M", localtime())
print printtime
pngname = "mapexport_" + printtime + ".png"
print pngname
# Set mxd
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
#Export PNG
arcpy.mapping.ExportToPNG(mxd, pngname, df, df_export_width = 1600, df_export_height = 1200, world_file = True)
#delete variables
del df, ws, printtime, pngname, mxd Suspect the issue is that you are sending a list of dataframes to the export command rather than just one df as ListDataFrames always produces a list, even if only one item in it. the above code will use the first dataframe in the list (index [0]). See if that gets it working, R_
... View more
08-14-2013
05:44 PM
|
0
|
0
|
1462
|
|
POST
|
This is working just fine for me.
<fields>
<field name="Shape_Area" alias="Area of Feature" visible="true">
<format precision="2" usethousandsseparator="true"/>
</field>
</fields> Of course, if I set it to "-1" I get the default, which is a whole ton of zeros. so, with it set to -1 37,441.89976562478 Set to "2": 37,441.90 R_ Works with my other numeric fields also. Just figured everyone can come up with a Shape_Area field to test. Though, I'm not using the description tag, so have not tested that part. Ok, just tested using the description tag. still working as expected.
... View more
08-14-2013
04:23 PM
|
0
|
0
|
883
|
|
POST
|
Could also just check to see if file exists, and size:
import os, stat
if os.path.isfile(infile): # checks if exists, otherwise get error if checking size on non-exist file
os.stat(infile)[stat.ST_SIZE] ## returns size of file 0L if empty
else:
print "file not exist"
This is done pretty much instantly.. R_
... View more
08-14-2013
02:46 PM
|
0
|
0
|
2700
|
|
POST
|
Sorry Michael, it seems I confused myself a bit. It was with indexes that I had this issue and had to work around it. For the joins, you just have to know what the name that was assigned to the join is, then it can be removed without error (just tested again in 10.1). â? If the join table was a dBASE file named MyTable.dbf, the join name would be "MyTable"; so to remove it, specify "MyTable". â? If the join table was an INFO or Geodatabase Table named MyTable2, the Join Name would be "MyTable2"; so to remove it, specify "MyTable2". â? The join name will not reflect the name of the table view itself, but rather the source of the table view. Therefore, if a table view is named TableView1 and points at mytable.dbf, the name of the join will be "mytable". My joins are to table(s) in FGDB so something like:
summary = "\\\\mcflight01\\MCFlightData\\rzworking\\script_baks\\wc98116\\update\\data_4_temp_services.gdb\\summary"
wids_full_buffer2 = "\\\\mcflight01\\MCFlightData\\rzworking\\script_baks\\wc98116\\update\\temp.gdb\\wids_full_buffer"
wastebuffers3 = "\\\\mcflight01\\MCFlightData\\rzworking\\script_baks\\wc98116\\update\\temp.gdb\\wastebuffers3"
arcpy.MakeFeatureLayer_management(wids_full_buffer2, wids_buffer_Layer, "", "", "")
arcpy.AddJoin_management(wids_buffer_Layer, "SITECODE", summary, "SITE_CODE", "KEEP_COMMON")
arcpy.AddJoin_management(wids_buffer_Layer, "SITECODE", wastebuffers3, "wids_full_buffer_SITECODE", "KEEP_COMMON")
arcpy.RemoveJoin_management(wids_buffer_Layer, "summary")
arcpy.RemoveJoin_management(wids_buffer_Layer, "wastebuffers3")
I can use either or both of the removes to remove thier respective joins (need to specify layer and join name). R_
... View more
08-14-2013
12:57 PM
|
0
|
0
|
3274
|
|
POST
|
I had a similar issue with joins that were set up on the data or mxd itself. All the joins that I added with python, I was able to remove individually by name. So, my workaround was to not have any initial joins, and create them all in the python script, then I can add/remove at will. R_
... View more
08-14-2013
11:15 AM
|
0
|
0
|
3274
|
|
POST
|
I was thinking of using arcpy.mapping to control a closed mxd. for real time pan of the display, this is that language (at least for the dataframe named "Layers"): mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] newExtent = df.extent newExtent.XMin = df.extent.XMin + deltaX newExtent.YMin = df.extent.YMin + deltaY newExtent.XMax = df.extent.XMax + deltaX newExtent.YMax = df.extent.YMax + deltaY df.panToExtent(newExtent) arcpy.RefreshActiveView() if you pass it a positive value for deltaY, it will pan the display north by the entered value (in map units), negative will shift south if you pass it a positive value for deltaX, it will pan the display East by the entered value (in map units), negative will shift west R_
... View more
08-14-2013
08:51 AM
|
0
|
0
|
3001
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-14-2026 04:00 PM | |
| 1 | 09-14-2022 07:53 AM | |
| 1 | 09-14-2022 08:23 AM | |
| 1 | 05-21-2026 08:53 AM | |
| 1 | 05-14-2026 04:28 PM |
| Online Status |
Offline
|
| Date Last Visited |
Wednesday
|