0

I'm creating a Python Toolbox using ArcGIS 10.5 that ultimately creates a new feature class and .lyr file from the layers in a current .mxd table of contents. I need the new feature class and .lyr file to take on the metadata from the original layer. I can import the metadata to the feature class using arcpy.ImportMetadata_conversion (i,"FROM_ARCGIS",fc_outname), but it isn't working for the .lyr file. The .lyr file metadata remains empty, while the feature class is populated as expected.

Relevant portion of current code:

arcpy.ImportMetadata_conversion (i,"FROM_ARCGIS",feature_class) 
if not arcpy.Exists(lyr_outname):
    arcpy.AddMessage("Creating .lyr file: {}\n".format(lyr_outname))
    lyr = arcpy.MakeFeatureLayer_management(feature_class, lyr_disp)
    arcpy.ApplySymbologyFromLayer_management(lyr, v)
    arcpy.ImportMetadata_conversion (feature_class,"FROM_ARCGIS",lyr)
    arcpy.SaveToLayerFile_management(lyr, lyr_outname)`

Even with the .lyr file created, I can't use any of the import metadata tools in desktop to successfully import the metadata. While they complete successfully, it remains empty. I can however manually import the new feature class, and right click on it, and save to layer file. This saves the metadata.

2
  • 2
    A layerfile is not a dataset, it is a pointer to a dataset, with preferred symbology. It should not be able to accept feature class metadata, because it is not a feature class.
    – Vince
    Commented Aug 21, 2019 at 0:25
  • 2
    But they do. Despite not being the same file type, .lyr files do accept feature class metadata. My question is how to make arcpy behave as Desktop does when creating a .lyr file from a feature class
    – Pdavis327
    Commented Aug 21, 2019 at 3:05

1 Answer 1

1

While this approach doesn't work directly, the metadata information is carried over in the .mxd layer. For instance, right clicking the layer and item description in the catalog shows there isn't any metadata. However, right clicking the item in the .mxd table of contents, then data, then item description, shows the full metadata populated as expected.

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.