Hello All, I am running into problems with UpdateLayer that I can???t figure out. My goal is to write a script that exports a shapefile from a FGDB and adds the field-aliases existing in the FGDB-FC to the shapefile. I have run through the steps in the interactive Python-window but now I am trying to make it into a tool. I only get as far as using arcpy.mapping.UpdateLayer before it crashes.Here is my code:# -*- coding: cp1252 -*- import arcview import arcpy, os arcpy.env.overwriteOutput = True #Setting up... arcpy.env.transferDomains = True arcpy.env.workspace = r"C:\GIS\ArcGIS\aliastest" #Getting parameters inFC = arcpy.GetParameterAsText(0) outshp = arcpy.GetParameterAsText(1) wp = arcpy.GetParameterAsText(2) #Converting arcpy.FeatureClassToFeatureClass_conversion(inFC, wp, outshp) #Saving original FC to layer arcpy.MakeFeatureLayer_management(inFC, "inFCLyr") arcpy.SaveToLayerFile_management("inFCLyr", "H_Orig04") #Saving converted shape to layer arcpy.MakeFeatureLayer_management(os.path.join(wp, outshp), "outShpvLyr") arcpy.SaveToLayerFile_management("outShpvLyr", "H_shp04.lyr") #Preparing to update and replace srcLayer = arcpy.mapping.Layer(r"inFCLyr") upLayer = arcpy.mapping.Layer(r"outShpvLyr") mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "*")[0] arcpy.mapping.AddLayer(df, srcLayer, "BOTTOM") arcpy.RefreshTOC() arcpy.RefreshActiveView() arcpy.mapping.UpdateLayer(df, upLayer, srcLayer, False)
It gets as far as the last line where it ends with: File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\mapping.py", line 1876, in UpdateLayer tc.ReplaceLayer(tl, rl) ValueError: DataFrameObject: Unexpected error
Don't know what causes this! From what I can tell I am not doing anything arcpy.mapping wasn't designed for. I tested to make sure the parameters going into UpdateLayer where of the correct type, so it shouldn't be that. For the last part of of the script, I will use replaceDatasoure to transfer aliases from the original FC to the exported shapefile. Once I get pass this... I'd be really happy for any help on this.Thanks!