I have feature layers that have a different name in the TOC then that they do in the GDB. I cannot change either of these and I need the name of the feature class from the GDB in order to make my model work. I have tried things such as parse path but I only get the name of the layer as it is in the TOC.
I have tried a few ArcPy/Python methods, but with my little knowledge of these things, I could not figure out how to get the GDB name as an output parameter.
I am using ArcMap version 10.3.1
Below I have added an example of my model and the code I last used to try and get the name.
import os
import arcpy
layer = arcpy.GetParameter(0)
print(os.path.basename(layer))
1 Answer 1
You are trying to treat a spatial dataset as if it is a normal file so you are accessing properties that are not appropriate (i.e. os.path.basename
).
I would use the Calculate value tool but you could easily adapt your existing script if you wish.
The Calculate value tool is set up as:
You would change the parameter highlighted in red to what every you are using, don't ignore the quotes around it.
arcpy.Describe(lyr).name