Edit Query Layer Metadata or Description?

171
2
04-09-2020 05:10 PM
AdrianMartinez
New Contributor

I'm trying to automate the creation of some query layers with a toolbox and I've run into a problem that has me stumped.  I need to save a particular string to each layer however I can't find a way to do it.  Ideally I'd just save it the description of the layer however it looks likes the description property of the layer class has been depreciated in ArcPro.  I attempted to alter the metadata however the query layers are created with metadata isReadOnly property set to true.  I can't seem to find a way to programmatically add metadata to it as a result of this.

Any suggestions?

0 Kudos
2 Replies
DanPatterson_Retired
MVP Esteemed Contributor
0 Kudos
AdrianMartinez
New Contributor

Yep, here is a code snippet

                layer = arcpy.MakeQueryLayer_management(input_database=self.conn, out_layer_name=layer_name, query=strSQL, oid_fields=["id"], srid='3857') #Fails with broken geometries
                map.addLayer(layer[0], "TOP")
               
                md = m.Metadata()
                md.title = layer_name
                md.description = filter
                l = m.Metadata(map.listLayers()[0].longName)

                if not l.isReadOnly:
                    l.copy(md)
                    l.save()
                else:
                    arcpy.AddMessage("Layer is read only.")

0 Kudos