Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

loop through a list of mxds (user input)

$
0
0
Hello, everybody!

I have adapted a script that changes the data sources of the layers in one mxd provided by user input.
All I want is to have this script accept multiple mxds from user and loop through the script.
I know this situations has been described before, however I was not able to implement the advice found here.
I am at the very beginning of my python experience, therefore any help on this would be much, much appreciated.
I paste in the code with my trial for multiple mxd input:

import arcpy

#set new SDE connection
newSdePath = r"Database Connections\myConnection.sde"

#get mxds as input from user
mxdAr = arcpy.GetParameterAsText(0)
mxd = arcpy.mapping.MapDocument(mxdAr)

#parse through the list of mxds, dataframes, layers; change data sources

for mxdItem in mxd.split(";"):
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd, ""):
if lyr.isFeatureLayer== True:
lyr.replaceDataSource(newSdePath, "SDE_WORKSPACE","", False)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
del mxd


The error i get :
File "D:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 608, in __init__
assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.


Thank you for your help!

Viewing all articles
Browse latest Browse all 2485

Trending Articles