0

I am trying to use ArcPy to create a data catalog of ArcGIS Pro projects.

Does anyone know how to extract the actual name of a layer (the name in the GDB) not just the alias?

This is my code so far

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Users\marco.conopio\Documents\MNL_07476032_ADM_Administrative\MNL_07476032_ADM_Administrative.aprx")
Maps=aprx.listMaps()[0]
for n in Maps.listLayers():
 print(n.name)

The output is just the name of the layer in the TOC but I also want the name of the layer in the GDB.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Dec 28, 2021 at 13:57
6
  • You've asked for the name of the layer, not the source. Commented Dec 28, 2021 at 14:03
  • yes i did. but i also want to asked for the name of the source. May I know what command should i use? Commented Dec 28, 2021 at 14:07
  • try print (n.datasetName) Commented Dec 28, 2021 at 15:03
  • Hi @GISDataButcher Thank you for the suggestion. I tried to it and it gave me this error AttributeError: 'Layer' object has no attribute 'datasetName' Commented Dec 29, 2021 at 10:58
  • @MarcoConopio what type layer it is? can you pls check it right click on layer it and paste path here Commented Dec 29, 2021 at 11:18

1 Answer 1

4

Take a look at the Layer documentation for ArcGIS Pro or ArcMap (since there are differences) to see if one (or two in combination) of the following layer properties are what you're looking for. Also consider splitting the full path and taking only the final portion if you don't find what you're looking for.

ArcGIS Pro Properties:

dataSource: Returns the complete path for the layer's data source. It includes the full workspace path and name of the dataset. For enterprise geodatabase layers, a string containing the layer's connection information is returned.

longName: A layer's full name including group layer and composite layer structure.

name: The name of a layer the way it would appear in the table of contents. Spaces can be included. It is important that all layers in a map have a unique name so they can be easily referenced by their names.

ArcMap Properties:

datasetName: Returns the name of the layer's dataset the way it appears in the workspace, not in the TOC. Not all layers support the datasetName property (for example, web services), so it is good practice to test for this ahead of time using the supports method.

dataSource: Returns the complete path for the layer's data source. It includes the workspacePath and the datasetName properties combined. Not all layers support the dataSource property (for example, annotation classes and web services), so it is good practice to test for this ahead of time using the supports method.

longName: This property is valuable when trying to determine whether a layer belongs to a group layer. If a layer does not belong to a group layer, the long name will equal the layer name. If a layer does belong to a group layer, the group layer structure will be included in the long name. For example, the name of a layer nested inside a group layer within another group layer may look something like Group1\Group2\LayerName. All layer types support this property.

name: Provides the ability to set or get the name of a layer the way it would appear in the ArcMap table of contents. Spaces can be included. All layer types support this property.

workspacePath: Returns a path to the layer's workspace or connection file. Not all layers support the workspacePath property (for example, web services), so it is good practice to test for this ahead of time using the supports method.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Dec 28, 2021 at 14:46
1
  • Thank you for this. The one I am looking for is the datasetName. Though it seems that this documentation is for Arcmap and not all commands are applicable in ArcGIS pro. I tried to use datasetName and this error was shown AttributeError: 'Layer' object has no attribute 'datasetName' Commented Dec 29, 2021 at 10:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.