Pyhton script for changing datasource in MXD

490
6
01-03-2014 03:10 AM
DianaVettori
New Contributor
Hi,

I wanted to change the datasource of layers in my mxd but my script is not doing this. I am using below:

lyr.replaceDataSource(layer.workspacePath,"SDE_WORKSPACE",newFeatureclassPath, False)


Please help if anybidy has done this before.

Thanks & Regards
Tags (2)
0 Kudos
6 Replies
AdamMarinelli
Occasional Contributor
This may be incorrect because I am just reading into your variable names...but the third parameter of 'replaceDataSource' should be {dataset_name} and not a file path: replaceDataSource (workspace_path, workspace_type, {dataset_name}, {validate}).

This resource will be helpful for mixing broken data sources if you have not seen it already:


Updating and fixing data sources with arcpy.mapping (arcpy.mapping)
http://resources.arcgis.com/en/help/main/10.1/index.html#/Updating_and_fixing_data_sources_with_arcp...
0 Kudos
DianaVettori
New Contributor
Hi ,

I appreciate your quick reply. thank you.
below is the parameters i am passing but still facing the issue.No idea what i am doing wrong.
  layer.ReplaceDatasource(FeatureDatasetPath", "SDE_WORKSPACE", "featureclassName",False)


FeatureDatasetPath(Path of featuredataset where featureclass resides) =r "\\server\Database Connections\dataLatest"
featureclassName=r"roadLatest"
This is what i am passing as parameters.

Regards
0 Kudos
AdamMarinelli
Occasional Contributor
Try changing the workspace_path parameter of the method to point to the actual '.sde' file.

Example:  r "\\server\Database Connections\dataLatest.sde"

To be sure you get the path and file extension correct, click on the database name in the Database Connections folder of the Catalog window of ArcMap.  Copy the path location name from the address bar at the top of the window.

EDIT: the workspace_path should point to the connection file (*.sde) and does not point to the file path of the feature dataset that your feature class is in.  This seems to throw an error for me.

Is there an error message when you run the code in ArcMap?
0 Kudos
TonyAlmeida
Occasional Contributor II
What works for me is to get the complete file path from ArcCatalog. Right click on the sde database and click "properties" and use the full path name under the General Tab:

Name: C:\Users\ComputerName\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\***.sde.
0 Kudos
DianaVettori
New Contributor
Hi amarinelli ,

It is working now... Thank you for the support
0 Kudos
MichaelVolz
Esteemed Contributor
For the .sde file for the database connection, is anyone trying to create this on the fly where a parameter of the connection might be changing such as the instance (e.g. sde:oracle10g:"SID" to sde:oracle11g:"SID")?

I am trying to perform this operation at v10.2 and it is taking between 29-35 seconds for the .sde file to be written to disk.  This same operation took a split second at v10.0.  This is a problem because I have over 200,000 sde connections to change in 10s of thousands of mxds and lyr files.
0 Kudos