AnsweredAssumed Answered

Acces Metadata for map service Arcpy

Question asked by EQUIPE-IS on Apr 18, 2015
Latest reply on Apr 19, 2015 by EQUIPE-IS

HI communauty geonet, and users,


I try to update the metadatas (summary, details, Authors, ...) of many mxds in a folder and when i execute my python script all is ok (no error).

When i have for exemple 3 mxds in a folder, and when i open the propriety of the first mxd in the list the information is ok.

But when i  open the second mxd the information in the case is null. And when Open Mapdocument the information is ok for this second mxd.

My problem is for my second script when a push the mxds in arcgis server. On the service map the information is ok for the first and not for the other. My code is this one (sorry for my english):



# -*- coding: cp1252 -*-

#import modules

import arcpy, sys, os, string

import xml.dom.minidom as DOM

import codecs



#Read parameters from dialog

filedoss = arcpy.GetParameterAsText(0)

u = arcpy.GetParameterAsText(1)

Summary = u.encode('cp1252', 'strict')

i = arcpy.GetParameterAsText(2)

Description = i.encode('cp1252', 'strict')

o = arcpy.GetParameterAsText(3)

Author = o.encode('cp1252', 'strict')

Credits = o.encode('cp1252', 'strict')

fileanc =  arcpy.GetParameterAsText(4)


MapPath= []

MapFolder = os.listdir(filedoss)

arcpy.env.workspace = filedoss

for file in MapFolder:

  fileExt = os.path.splitext(file)[1]

  if fileExt == ".mxd":

  MapPath = os.path.join(filedoss, file)

  arcpy.AddMessage (MapPath)

  #set map document to change

  mxd = arcpy.mapping.MapDocument(MapPath)

  base = os.path.basename(filedoss).upper()


  #Nouveau nom

  file_name_temp = "NOM_" + base + "_" + file 


  #arcpy.AddMessage ("MXD a sauvegarder :" + file_name)

  arcpy.AddMessage ("MXD sauvegarde :"  + file_name_temp)

  # Test existence de la sauvegarde

  if os.path.exists(file_name_temp):

  arcpy.AddMessage("Fichier mxd existe")

  try :

  # essaye de le supprimer


  except :

  arcpy.AddError ("Fichier non sauvegarde : impossible de le supprimer")



  #change Title

  mxd.title = file_name_temp

  #change Summary

  mxd.summary = Summary

  #change Description

  mxd.description = Description

  #change Author = Author

  #change credits

  mxd.credits = Credits


  #Update map document tags

  #Generate unique, sorted list of layer names

  layers = arcpy.mapping.ListLayers(mxd)

  layerList = []

  for lyr in layers:

  if not lyr.isGroupLayer:


  uniqueList = list(set(layerList))



  #Update map document tags

  tagList = ",".join(uniqueList) 

  mxd.tags = tagList

  for lyr in layers:

  if lyr.supports("DATASOURCE"):

  lyr.replaceDataSource(filedoss, 'SHAPEFILE_WORKSPACE', lyr.datasetName, False)


  #set relative paths property

  mxd.relativePaths = True



  #update Thumbnail





  #save map document change

  #SAuvegarde sous nouveau


  arcpy.AddMessage ("Fichier sauvegarde")





del mxd