1
$\begingroup$

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'}
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}

    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")
$\endgroup$

1 Answer 1

1
$\begingroup$

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)
    else:
        col.label('An empty selected')

enter image description here

$\endgroup$
1
  • $\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$ Commented Jan 5, 2016 at 18:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .