Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to replace the datasource for all of the layers in my map document using Python but I keep running into an error. Right now, all of the layers point to a feature class called GISDB.DBO.TESTFEATURECLASS and I want them to point to a view that I built using the sdetable -o createview command. It has both the object id and geometry columns from the original feature class. It shows up in ArcCatalog with the same icon as a feature class and I can add it as a layer in ArcMap.

Runtime error <type 'exceptions.ValueError'>: Layer: Unexpected error

mapdoc = arcpy.mapping.MapDocument("CURRENT")
workspace_path = r'Database Connections\TestGIS.sde'
workspace_type = "SDE_WORKSPACE"
dataset_name = r'GISDB.DBO.TESTFEATURECLASS_VIEW'
for layer in arcpy.mapping.ListLayers(mapdoc):
    layer.replaceDataSource(workspace_path, workspace_type, dataset_name)

How can I determine which property is causing the error?

share|improve this question
    
I had some troubles with .replaceDataSource when doing layer repointing in an mxd with arcpy. I think some of the problem was updating the mxd and saving it. You may be repathing it but then you don't save it. I'll try to find some code that ended up working for me. –  Justin Jul 20 '12 at 3:28
1  
arcpy.mapping.UpdateLayer(p1,p2,p3,false) ...may also help. p1 is parameter 1. –  Justin Jul 20 '12 at 4:04
    
I asked a similar question a while ago gis.stackexchange.com/questions/29185/…, I was getting the same error as you. Turns out I had to add mxd.save() at the end to ensure the data source was replaced. –  Cindy Williams Jul 20 '12 at 11:46
    
@Arabella I ran into the save error when I replaced the layer workspaces from a Python window in ArcCatalog. I think the problem there was that I hadn't allowed the mxd file to be closed because closing all instances of ArcCatalog and ArcMap and starting fresh allowed me to make my changes and save them. –  jrockers Jul 23 '12 at 15:05
    
@Justin updateLayer would work but I don't want to replace the symbology. I think the underlying problem is that the string I'm using for either the workspace or the datasetName is wrong but I don't know where to find the correct string. Thanks for your comments. –  jrockers Jul 23 '12 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.