Rename Selected objects

This script is very short in the sense that there is only one line of blender code object.name = textfield.value to rename object.

In this step we simply rename active object.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import bpy
from boss.ui_creator import TextField, UICreator, Boss_OT_base_ui


def renameObj(caller: TextField):
    caller.param.name = caller.value


def ui_elements(op: Boss_OT_base_ui):
    UICreator.deleteAllUi(op)  #  delete any existing UI

    o = bpy.context.object

    mouse_x, mouse_y = UICreator.mouse_xy(op)

    rd = (mouse_x, mouse_y - 25, 200, 25)

    UICreator.textField(op, rd, text=o.name, param=o, onValueChange=renameObj)