mbishopp

Problem changing paths of featureclasses in feature dataset using arcpy

Discussion created by mbishopp on Oct 12, 2010
Latest reply on Apr 4, 2017 by clothonite
I am trying to change a path from Oracle SDE to SQL Server SDE.  The feature classes that I am trying to repath are found within featuredatasets.  The basic code that I am using is:


                          
 mxd = arcpy.mapping.MapDocument(fullpath)
                        
                            DFList = arcpy.mapping.ListDataFrames(mxd)
                    
                            for df in DFList:
                                lyrList = arcpy.mapping.ListLayers(mxd, "", df)
                    
                                for lyr in lyrList:
                                    if lyr.supports("DATASOURCE"):
                                        
                                        sourcePath = os.path.dirname(lyr.dataSource)
                                        
                                        if lyr.dataSource.count(".sde") > 0:

                                           mxd.findAndReplaceWorkspacePaths(sourcePath,
                                           r"Database Connections\Test_CartaTest_GISUSER.sde\CartaTest.TRANS.BikeFeatures") #change to Carta instead of CartaTest when done
                    


The original data is found in "Database Connections\GIS_USER2PGIS.sde\TRANS.BikeFeatures.
The new data (as shown above) needs to be repathed to: "Database Connections\Test_CartaTest_GISUSER.sde\CartaTest.TRANS.BikeFeatures

Can anyone tell me if this is the correct approach?  Would it be better to do something like this:

lyr.replaceDataSource(r"Database Connections\Test_CartaTest_GISUSER.sde\CartaTest.TRANS.BikeFeatures", "SDE_WORKSPACE", "BikeFeatures") <--BTW, this exact syntax doesn't work.

Outcomes