I made a small modal operator that prints the name of the object I select. however each selection made is one object behind.
example:
select object 1 then select object 2. when object 2 is selected it will print the name of object 1.
code:
# Import
import bpy
# Properties
class Blank(bpy.types.Operator):
bl_label = "Blank"
bl_idname = "blank.example"
# TESTING ##################################################################
def modal(self, context, event):
if (event.type in 'LEFTMOUSE' and event.value == 'RELEASE'):
# name = bpy.context.active_object.name
name = bpy.context.object.name
print(name)
if event.type == 'ESC':
return{'CANCELLED'}
return{'PASS_THROUGH'}
def invoke(self, context, event):
context.window_manager.modal_handler_add(self)
return{'RUNNING_MODAL'}
############################################################################
# Menu on the Sidebar
class Blank_PT_Panel(bpy.types.Panel):
bl_label = "Panel"
bl_idname = "OBJECT_PT_Blank"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Blank"
bl_context = "objectmode"
def draw(self, context):
layout = self.layout
# Button
row = layout.row(align=True)
row.operator("blank.example", text="Button", icon="QUESTION")
# Registration
classes = (
Blank_PT_Panel,
Blank,
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
if __name__ == "__main__":
register()
How do you make the selection display the name of the object without any delay.
P.S. Code edited to run from the Blender Text Editor as requested. it creates a tab called blank on the Sidebar(N-menu) and a single button inside. Press it to run the code in question.