With the following code I can read out the name of a mesh data block.

row.prop(obj, "data")

And with the following code I can read out the name of the object.

row.prop(obj, "name")

But I noticed that I cannot edit the mesh data name only the object name.

enter image description here

Here is the code from Blender that generated the mesh data block UI.

class DATA_PT_context_mesh(MeshButtonsPanel, Panel):
    bl_label = ""
    bl_options = {'HIDE_HEADER'}

    def draw(self, context):
        layout = self.layout

        ob = context.object
        mesh = context.mesh
        space = context.space_data

        if ob:
            layout.template_ID(ob, "data")
        elif mesh:
            layout.template_ID(space, "pin_id")

Think of Objects as containers, which can contain Curve data or Mesh data (and a few other kinds).

obj.data will refer to the Mesh or the Curve of the object. You would need to do the following to display the mesh's name

row.prop(obj.data, "name")

Or replicating what the standard panels do (with or without the icon).

    obj = context.object

    col = layout.column()
    if obj.data:
        col.prop(obj.data, "name")
        col.prop(obj.data, "name", icon="OUTLINER_DATA_" + obj.type)
        col.label('An empty selected')

enter image description here

  • $\begingroup$ Thank your very much. I learned a lot in the past days. I start to understand now how my students must feel when I teach Blender and they are new to it. There is a lot to take in. $\endgroup$ – Claas Kuhnen Jan 5 '16 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.