POST
|
I don't think the current problem is to refresh, the script loops through a folder to apply it to every mxd. But your idea isn't bad, I would have to create a .lyr for each mxd then add some lines to the script to use this new .lyr only to set visibility... Now I have to find how to do it!
... View more
04-14-2016
03:53 PM
|
0
|
0
|
908
|
POST
|
Gave it a try, but it didn't work... The good side: there's is no error message.
... View more
04-14-2016
02:51 PM
|
0
|
2
|
908
|
POST
|
Hello, The following script works perfectly to update all mxds contained in one folder using a unique .lyr file as a reference to all layers (in groups and subgroups). All mxds have the same TOC composition, but the visibility of each layer depend of the mxd. My problem is that when I run the "update script", the .lyr file apply his parameter to the layers so it turns them OFF. The .lyr file contains only OFF layers because, as I said, the visibility of every layer is different in each map project. So I would love to find a way to integrate a few more lines of code in the script so it would list the layers visibility parameter (for every layers in the mxd), then do the update, finally toggle back ON the layers that were ON initially using the list. I found something, but I can't find a way to integrate it in the "update script" (http://gis.stackexchange.com/a/158476/69986). Here the "update script":
import arcpy
import os
MxdFolderPath = arcpy.GetParameterAsText(0)
if MxdFolderPath == '#' or not MxdFolderPath:
MxdFolderPath = "//10.13.77.8/MRC_doc/20_Territoires/20-4000_Schema_Amen_Dev/20-4100_Planification/20-4120_Projet_SAD/20-4121_Projet_SAD/Y_Cartographie/A_Planches/Mise_a_jour/Test"
MxdCount = 0
sourcelypath = arcpy.GetParameterAsText(1)
if sourcelypath == '#' or not sourcelypath:
sourcelypath = "//10.13.77.8/MRC_doc/20_Territoires/20-4000_Schema_Amen_Dev/20-4100_Planification/20-4120_Projet_SAD/20-4121_Projet_SAD/Y_Cartographie/A_Planches/Fichiers .lyr/Autres formats/Couches.lyr" # reference .lyr file
sourcely = arcpy.mapping.Layer(sourcelypath)
arcpy.env.workspace = MxdFolderPath
arcpy.AddMessage(" MXD PROCESSING")
mxdList = arcpy.ListFiles("*.mxd")
Mxdlen = len(mxdList)
if Mxdlen == 0:
arcpy.AddMessage(" There are no mxd in: " + str(MxdFolderPath))
else:
arcpy.AddMessage(" There are " + str(Mxdlen) + " mxd in: " + str(MxdFolderPath))
for mxd in mxdList:
MxdCount = (MxdCount + 1)
MxdPPath = os.path.join(MxdFolderPath, mxd)
processingmxd = arcpy.mapping.MapDocument(MxdPPath)
arcpy.AddMessage(" Mxd: " + str(MxdCount) + " :" + str(mxd))
dflist = arcpy.mapping.ListDataFrames(processingmxd, "Couches_DF") # Dataframe
for df in dflist:
arcpy.AddMessage(" df: " + str(df.name))
layers = arcpy.mapping.ListLayers(processingmxd, "Couches", df) # layers called Couches
for layer in layers:
arcpy.AddMessage(" Layer: " + str(layer))
arcpy.mapping.UpdateLayer(df, layer, sourcely, False)
arcpy.AddMessage(" Layer Updated")
processingmxd.save()
arcpy.AddMessage(" ")
arcpy.AddMessage(" End") Can anyone help? Thanks in advance!
... View more
04-14-2016
01:40 PM
|
0
|
9
|
3088
|
POST
|
import arcpy
import os
#delete any data tha might be stored in memory
arcpy.Delete_management("in_memory")
#set workspace to where all your shapefiles are
arcpy.env.workspace="C:/Users/Antoine/Desktop/MRCL - Local/Ketar_shp"
#define where the hydro shapefile is located, ideally in a different folder than the others
hydroshp="C:/Users/Antoine/Desktop/MRCL - Local/Ketar_shp/hydro/hydro.shp"
fcs=arcpy.ListFeatureClasses()
for fc in fcs:
#create an empty list to be populated with the original shapefile's field names
fieldnames=[]
#List all fields in the shapefile and populate the fieldnames list with their names
fields=arcpy.ListFields(fc)
for field in fields:
fieldnames.append(field.name)
#define layer name for each shapefile
fclayer=fc.rstrip(".shp")
#create output files for the clip and the union layers
fcClip=os.path.join("in_memory",fclayer+"clip")
fcUnion=fclayer+"union.shp"#os.path.join("in_memory",fclayer+"union")
#clip the shapefile using the hydro layer
arcpy.Clip_analysis(fc,hydroshp,fcClip)
#create a union of the clipped hydro and the shapefile
arcpy.Union_analysis([fc,fcClip],fcUnion,"ALL")
#delete any unnecessary fields from your union shapefile
unionfields=arcpy.ListFields(fcUnion)
for ufield in unionfields:
if ufield.name not in fieldnames:
arcpy.DeleteField_management(fcUnion,ufield.name)
#Create layer file so you can perform a selection on it
arcpy.MakeFeatureLayer_management(fcUnion,fclayer+"_sansO")
arcpy.SelectLayerByLocation_management(fclayer+"_sansO","WITHIN",fcClip)
#If selection > 0, delete features
if int(arcpy.GetCount_management(fclayer+"_sansO").getOutput(0)) > 0:
arcpy.DeleteFeatures_management(fclayer+"_sansO")
#export data layerName_union as shapefile (works)
arcpy.FeatureClassToFeatureClass_conversion(fclayer+"_sansO","C:/Users/Antoine/Desktop/MRCL - Local/Ketar_shp/shapes_sansO.gdb",fclayer+"_sansO")
print "done!!" Someone helped me, here's what we have come up with!
... View more
04-14-2016
01:21 PM
|
1
|
0
|
993
|
POST
|
Working! Now, I have to figure out how to insert a folder crawl. Thanks everyone!
import arcpy
import os
MxdFolderPath = arcpy.GetParameterAsText(0)
if MxdFolderPath == '#' or not MxdFolderPath:
MxdFolderPath = "C://Users//enclume//Carto//Cartes//UpdateTest"
MxdCount = 0
sourcelypath = arcpy.GetParameterAsText(1)
if sourcelypath == '#' or not sourcelypath:
sourcelypath = "C://Users//enclume//Carto//Cartes//Templates//Couches.lyr"
sourcely = arcpy.mapping.Layer(sourcelypath)
arcpy.env.workspace = MxdFolderPath
arcpy.AddMessage(" MXD PROCESSING")
mxdList = arcpy.ListFiles("*.mxd")
Mxdlen = len(mxdList)
if Mxdlen == 0:
arcpy.AddMessage(" There are no mxd in: " + str(MxdFolderPath))
else:
arcpy.AddMessage(" There are " + str(Mxdlen) + " mxd in: " + str(MxdFolderPath))
for mxd in mxdList:
MxdCount = (MxdCount + 1)
MxdPPath = os.path.join(MxdFolderPath, mxd)
processingmxd = arcpy.mapping.MapDocument(MxdPPath)
arcpy.AddMessage(" Mxd: " + str(MxdCount) + " :" + str(mxd))
dflist = arcpy.mapping.ListDataFrames(processingmxd, "Couches")
for df in dflist:
arcpy.AddMessage(" df: " + str(df.name))
layers = arcpy.mapping.ListLayers(processingmxd, "Couches", df) # layers called Couches
for layer in layers:
arcpy.AddMessage(" Layer: " + str(layer))
arcpy.mapping.UpdateLayer(df, layer, sourcely, False)
arcpy.AddMessage(" Layer Updated")
processingmxd.save()
arcpy.AddMessage(" ")
arcpy.AddMessage(" End")
... View more
04-06-2016
08:37 AM
|
0
|
0
|
760
|
POST
|
The identation is a copy/paste problem. It's probably my web browser but once code is added in a comment/post, it appears all messed up. Code lines are doubled and overlapping, I can't modify it. Originally it is indented as shown here:
... View more
04-05-2016
06:56 PM
|
0
|
1
|
760
|
POST
|
On another forum, someone wrote me the following code: import arcpy
MxdFolderPath = arcpy.GetParameterAsText(0)
if MxdFolderPath == '#' or not MxdFolderPath:
MxdFolderPath = "C://Users//enclume//Carto//Cartes//UpdateTest"
MxdCount = 0
sourcelypath = arcpy.GetParameterAsText(1)
if sourcelypath == '#' or not sourcelypath:
sourcelypath = "C://Users//enclume//Carto//Cartes//Templates//Couches.lyr"
sourcely = arcpy.mapping.Layer(sourcelypath)
arcpy.env.workspace = MxdFolderPath
arcpy.AddMessage(" MXD PROCESSING")
mxdList = arcpy.ListFiles("*.mxd")
Mxdlen = len(mxdList)
if Mxdlen == 0:
arcpy.AddMessage(" There are no mxd in: " + str(MxdFolderPath))
else:
arcpy.AddMessage(" There are " + str(Mxdlen) + " mxd in: " + str(MxdFolderPath))
for mxd in mxdList:
MxdCount = (MxdCount + 1)
processingmxd = arcpy.mapping.MapDocument(mxd)
arcpy.AddMessage(" Mxd: " + str(MxdCount) + " :" + str(mxd))
dflist = arcpy.mapping.ListDataFrames(processingmxd, "Couches")
layercount = 0
for df in dflist:
arcpy.AddMessage(" df: " + str(df.name))
layers = arcpy.mapping.ListLayers(processingmxd, "Couches", df) # layers called Couches
for layer in layers:
layercount = (layercount + 1)
arcpy.AddMessage(" Layer: " + str(layer))
arcpy.mapping.UpdateLayer(df, layer, sourcely, False)
arcpy.AddMessage(" Layer Updated")
processingmxd.save()
arcpy.AddMessage(" ")
arcpy.AddMessage(" End") Seems good, but I get an error message: Traceback (most recent call last): File "<string>", line 24, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\arcobjects\mixins.py", line 611, in init assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename") AssertionError: Invalid MXD filename Can anyone see where is the problem?
... View more
04-05-2016
06:35 PM
|
0
|
3
|
760
|
POST
|
I added "mxd.save()" in the end. Solved the first problem, thanks!
... View more
04-05-2016
05:14 PM
|
1
|
1
|
760
|
POST
|
Part A: I'm trying to use the code above to update layers in a mxd using a .lyr file. These layers are in a dataframe named "Couches" (there is another dataframe in the mxd). Code comes from this post. import arcpy.mapping as mmap
mxd = mmap.MapDocument("C:/Users/enclume/Carto/Cartes/UpdateTest/P_5_1.mxd")
DF = mmap.ListDataFrames(mxd, "Couches")[0]
sourcely = mmap.Layer("C:/Users/enclume/Carto/Cartes/Templates/Couches.lyr")
ly = mmap.ListLayers(mxd)[1]
mmap.UpdateLayer(DF, ly, sourcely, False) When I run the code everything seems fine, no error message. But when I open the mxd, nothing has changed. What am I doing wrong? Part B: Once the problem is solved, I would like to loop this code so that it would update all mxd's in a file. How would you proceed to loop it? I saw some stuff here, but I'm far from really understanding how to apply this example to my situation. The person who wrote the code linked above mentioned the glob.glob function to loop it, but I can't find anything about it. Does anyone know how to use it? If my mxd's folder ("C:/Users/enclume/Carto/Cartes/UpdateTest") contains some subfolders, will the looping function find all the mxd's in the folder and subfolders? I'm new to arcpy so please be indulgent and precise... Thanks in advance !
... View more
04-05-2016
04:46 PM
|
0
|
8
|
3800
|
POST
|
Only workaround I found: using .png files... Not great, because you can't change the color of the marker in ArcGIS, you have to use another software. This problem is pretty anoying, someone at ESRI should look at this bitmap / pdf export issue.
... View more
04-05-2016
03:06 PM
|
0
|
2
|
3027
|
POST
|
When I try it exactly like you posted I get an error message, but my guess is that I'm doing something wrong... What is the fm.outputField? Should I replace "out_stuff" by something?
... View more
03-29-2016
06:59 AM
|
0
|
4
|
339
|
POST
|
Thanks again, but the bitmap markers in question do not contain any character/font symbols... Most of the time, they appear in the legend but not in the map itself.
... View more
03-29-2016
06:19 AM
|
0
|
0
|
3027
|
Title | Kudos | Posted |
---|---|---|
1 | 04-05-2016 05:14 PM | |
1 | 04-14-2016 01:21 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|