disable placing text if not possible

This commit is contained in:
themancalledjakob 2024-08-04 13:32:01 +02:00
parent 3ecd3177c1
commit 2d8ec86edc

View file

@ -277,6 +277,16 @@ class FONT3D_PT_TextPlacement(bpy.types.Panel):
bl_space_type = "VIEW_3D" bl_space_type = "VIEW_3D"
bl_region_type = "UI" bl_region_type = "UI"
can_place = False
@classmethod
def poll(self, context):
if type(context.active_object) != type(None) and context.active_object.type == 'CURVE':
self.can_place = True
else:
self.can_place = False
return True
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
wm = context.window_manager wm = context.window_manager
@ -289,7 +299,12 @@ class FONT3D_PT_TextPlacement(bpy.types.Panel):
layout.row().prop(font3d, "text") layout.row().prop(font3d, "text")
layout.row().prop(font3d, "letter_spacing") layout.row().prop(font3d, "letter_spacing")
layout.column().prop(font3d, "orientation") layout.column().prop(font3d, "orientation")
layout.row().operator('font3d.placetext', text='Place Text') placerow = layout.row()
placerow.enabled = self.can_place
placerow.operator('font3d.placetext', text='Place Text')
if not self.can_place:
layout.label(text="Cannot place Text.")
layout.label(text="Select a curve as active object.")
class FONT3D_PT_TextManagement(bpy.types.Panel): class FONT3D_PT_TextManagement(bpy.types.Panel):
bl_label = "Text Management" bl_label = "Text Management"
@ -474,7 +489,7 @@ class FONT3D_OT_TemporaryHelper(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
class FONT3D_OT_PlaceText(bpy.types.Operator): class FONT3D_OT_PlaceText(bpy.types.Operator):
"""Place Text 3D""" """Place Text 3D on active object"""
bl_idname = f"{__name__}.placetext" bl_idname = f"{__name__}.placetext"
bl_label = "Place Text" bl_label = "Place Text"
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}