Message posté par : PauloLrx
----------------------------------------
Bonjour Jérémy,
On m'a aidé a modifier le code mais pas sur que ce soit pour une version plus récente
de arcpy
Pourriez-vous y jetter un oeuil s'il vous plait?
Voici :
-----------------
Code :
import arcpy
import arcpy.mapping as m
import os
root_folder = r"path\to\root\folder"
add_lyr_1 = r"path\to\file1.lyr"
add_lyr_2 = r"path\to\file2.lyr"
add_lyr_3 = r"path\to\file3.lyr"
## create list of lyr files
add_lyrs = [add_lyr_1, add_lyr_2, add_lyr_3]
mxd_paths = []
## add all mxd paths to a list
for root, dirs, files in os.walk (root_folder):
for f in files:
if f.endswith(".mxd"):
mxd_paths.append("{0}\\{1}".format(root, f))
## print to test
#print(mxd_paths)
for mxd_doc in mxd_paths:
mxd_name = mxd_doc.rsplit("\\")[-1]
arcpy.AddMessage(mxd_name)
## access the mxd
mxd = m.MapDocument(mxd_doc)
## only access the desired dataframe
## you might want to use a dataframe name / wildcard to
## add layers to correct dataframe if you have multiple
df = m.ListDataFrames(mxd)[0]
## add each layer file, one on top of the other.
for lyr_file in add_lyrs:
add_lyr = m.Layer(lyr_file)
m.AddLayer(df, add_lyr ,"TOP")
mxd.save()
-----------------
----------------------------------------
Le message est situé
https://georezo.net/forum/viewtopic.php?pid=354213#p354213
Pour y répondre : esri_fr(a)ml.georezo.net ou reply de votre messagerie
Pour vous désabonner connectez-vous sur le forum puis Profil / Abonnement
--
Association GeoRezo - le portail géomatique
https://georezo.net