6

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....

2
  • I would expect this to work so are you able to post some code for your steps to be tested, please?
    – PolyGeo
    Commented May 22, 2013 at 21:22
  • Hey - old post, but did you end up filing this as a bug with ESRI? I'm having this same issue with 10.3.1. Thanks! Commented Jan 22, 2016 at 20:20

1 Answer 1

1

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!

import arcpy

path_to_blankmxd = r"C:\temp\test.mxd"
featureclass_gdb = r"C:\temp\test.gdb\testFC"
activation = "XX2"
layername = "test"
featureclass = "Poly"

mxd=arcpy.mapping.MapDocument(path_to_blankmxd)
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
arcpy.MakeFeatureLayer_management(featureclass_gdb,activation+"_"+featureclass)

addLayer=arcpy.mapping.Layer(activation+"_"+featureclass)
addLayer.name=layername
arcpy.mapping.AddLayer(df,addLayer)
mxd.save()
del mxd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.