I have multiple feature classes in a geodatabase, each feature class has metadata including a Description, Credits, and other information. If I use the 'Add Data' button in ArcMap 10.1 to add one of feature classes then that metadata is imported into the layer description. Ie, I view the layer properties and Description, Credits, etc., are filled in. However, if I use arcpy and add the feature class using MakeFeatureLayer_management
and AddLayer
then that metadata is not imported.
Does anyone know if its possible to get that full functionality of feature classes and their description, credits, etc to load with arcpy? Am I doing something wrong? Or, must I export the metadata, read the sections I want, and add that text to the layer file?
As requested, a code sample is:
mxd=arcpy.mapping.MapDocument(path_to_blankmxd)
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
arcpy.MakeFeatureLayer_management(featureclass_sde,activation+"_"+featureclass)
addLayer=arcpy.mapping.Layer(activation+"_"+featureclass)
addLayer.name=layername
arcpy.mapping.AddLayer(df,addLayer)
The feature class to be inserted in the MXD is 'featureclass_sde' with full metadata. However, once its inserted all metadata is lost. At present I am exporting metadata as XML, parsing XML to get metadata elements (description, source, etc), and then inserting those elements into the MXD. It works but seems so…. wrong….
Best Answer
I agree that this appears to be a bug with AddLayer and so I think you should report it to your local Esri Support.
I was able to reproduce it easily by creating a file geodatabase, creating a feature class within it, and then using Item Description to Edit its Metadata including Credits.
When I drag and dropped this feature class into the map it created a layer that had the Credits on the General tab of its Properties - as expected.
However, when I ran the code below (based on yours) and looked in ArcMap at the layer thus created by AddLayer the expected Credits were missing!