Select to view content in your preferred language

replace data sources script not returning to for loop

3570
5
01-18-2011 10:29 AM
by Anonymous User
Not applicable
Original User: jgustine

I am having a problem with the attached script and was hoping someone sees something I don't. We did a large data migration from shapefiles in a fileshare to a single SDE database for one of our customers. My goal is to automate the repathing process with script that loops thru the MXD directories and uses the replaceDataSource method to insert the new data sources.

The attached script reads from a text file (also attached) to check for and change data source info. It sucessfully runs thru and replaces the 1st layer in each map document, but will not continue to the next?

Anyone see any syntax/indentation problems. Thanks
0 Kudos
5 Replies
DuncanHornby
MVP Notable Contributor
James,

I'm not so hot with Python but do you need to reset your position in your text file, some sort of reset pointer to beginning of text file?

Duncan
0 Kudos
by Anonymous User
Not applicable
Original User: jgustine

Thanks, that actually helped alot. Instead  of opening the text file at the begining of the script it needed to be opened within the "for lyr in lyrList" loop. Here's the working script if anyone's interested. Just need to add in some error logging.

Thanks again
0 Kudos
by Anonymous User
Not applicable
If you're still interested, I took this a little farther, maybe overkill but...

It will use a text file for input or from command line. It will also walk a directory structure.

c:\Temp>cls && python changedatasource.py --help to see the options.

Text file looks like:
# Layername or Source, Layername or SourcePath, Connect To, Featureclass
Layername,Artwork,Database Connections\PublicUser.sde,SDE.Artwork
Source,C:\Documents and Settings\user\Application Data\ESRI\ArcCatalog\publicuser.sde\SDE.BaseMap\SDE.Call_Box,Database Connections\user.sde,SDE.Call_Box


Syntax for file input would be:
c:\Temp>cls && python changedatasource.py --dirpath c:\temp --norecurse --infile c:\temp\replace.txt --filelist c:\temp\test.mxd


Syntax for command line would be:
c:\Temp>cls && python changedatasource.py --dirpath c:\temp --norecurse --filelist c:\temp\test.mxd --dest "Layername,Artwork,Database Connections\PublicUser.sd
e,SDE.Artwork" --force


A note about the sample syntax. If --filelist is specified, --dirpath and --norecurse are ignored.
0 Kudos
by Anonymous User
Not applicable
Original User: cgnadinger

I am working on this right now and was having issues with the Database Connection to our servers.

This is working for the initial layer but I'm struggling with additional layers .. but it's progress further than where I was at least.



If you're still interested, I took this a little farther, maybe overkill but...

It will use a text file for input or from command line. It will also walk a directory structure.

c:\Temp>cls && python changedatasource.py --help to see the options.

Text file looks like:
# Layername or Source, Layername or SourcePath, Connect To, Featureclass
Layername,Artwork,Database Connections\PublicUser.sde,SDE.Artwork
Source,C:\Documents and Settings\user\Application Data\ESRI\ArcCatalog\publicuser.sde\SDE.BaseMap\SDE.Call_Box,Database Connections\user.sde,SDE.Call_Box


Syntax for file input would be:
c:\Temp>cls && python changedatasource.py --dirpath c:\temp --norecurse --infile c:\temp\replace.txt --filelist c:\temp\test.mxd


Syntax for command line would be:
c:\Temp>cls && python changedatasource.py --dirpath c:\temp --norecurse --filelist c:\temp\test.mxd --dest "Layername,Artwork,Database Connections\PublicUser.sd
e,SDE.Artwork" --force


A note about the sample syntax. If --filelist is specified, --dirpath and --norecurse are ignored.
0 Kudos
ChristinaGnadinger
Emerging Contributor
Any help someone could give me would by most appreciated!

I've replied with a few kinks I'm having here .. http://forums.arcgis.com/threads/49038-replaceDataSource-connecting-to-SDE-Instance?p=168862&viewful...
0 Kudos