Saturday 30 December 2017

Removing a Table from several MXD-Files using ArcPy


I'm trying to remove a certain Table (xlsx-File) from some MXD-Files using python, but I can't finguring out how.


I tried the code sniplet for removing:


import arcpy, os
from arcpy import env

arcpy.env.workspace = 'V:/Projects/ZEL'


mxd =arcpy.mapping.MapDocument('V:/Projects/ZEL/test04.mxd')

df=arcpy.mapping.ListDataFrames(mxd, 'u')[0]

for lyr in arcpy.mapping.ListLayers(mxd, '', df):
if lyr.name.lower()=='header_vorlage$':
if lyr.dataSource == 'V:\Projects\ZEL\SHP\Daten_111004\ZEL_LB_Tabelle_V3_2010_2030.xlsx':
arcpy.mapping.RemoveLayer(df, lyr)



mxd.saveACopy('pt.mxd')

print 'fertig'

del mxd

It works, but when I open the new created 'pt.mxd' there is still the symbol of the xlsx-Table with an '!' and you have the option to fix the datasource, because I have removed the path, but not the table...


I hope its not too confusing :)


My question is: Is there a way to remove a xlsx-Sheet from MXD-File without opening?





No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...