I'm creating an Add-on where you have to select any object type to start using it. but I would like to know if is there any way to display a red property input if no object is selected or exists.
- This image is an screenshot of driver editor pop-up
Yes. Just set Layout.alert
property to True
in case there is no object selected:
Demo based on @batFINGERs answer to Object selection box with eyedropper.
import bpy
from bpy.props import PointerProperty
class TEST_PT_layout_panel(bpy.types.Panel):
bl_label = "Prop Panels"
bl_category = "Test Panel"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
scene = context.scene
layout = self.layout
col = layout.column()
if not scene.prop:
col.alert = True
else:
col.alert = False
col.prop(scene, "prop")
def register():
bpy.types.Scene.prop = PointerProperty(type=bpy.types.Object)
bpy.utils.register_class(TEST_PT_layout_panel)
def unregister():
bpy.utils.unregister_class(TEST_PT_layout_panel)
if __name__ == "__main__":
register()