In this post Is it possible to get the property name from a data_path? I am able to get the field names from RMB > Copy Data Path in all object properties as well as their modifier name fields using this code:
def get_property_name(data_path) -> str:
s = data_path
i = s.find('.')
data_path_1 = ""
data_path_2 = data_path
if i > 0:
ri = s.rindex('.')
data_path_1 = '.' + s[0:ri]
data_path_2 = s[ri+1:len(s)]
data_block = "bpy.context.object"
data = eval(data_block + data_path_1)
return data.rna_type.properties[data_path_2].name if hasattr(data, data_path_2) else ''
Unfortunately if you change the line data_block = "bpy.context.object"
with, for example the default material of the default cube named Material value to line data_block = 'bpy.data.materials["Material"]'
and then call the function with any node field's data path, it will always return the same name Default Value. For example, the data path for the node field Subsurface Radius is node_tree.nodes["Principled BSDF"].inputs[2].default_value
and will return the name Default Value instead of Subsurface Radius as will all the other node fields. Is there any other way how we can retrieve the node field name?