You can define bl_property
and then a string property inside an operator using the same name, then use invoke function to return a pop-up (window_manager.invoke_props_dialog
). Here is an example based on Operator Simple template from the Text Editor's Templates menu:
import bpy
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
bl_property = "u_input"
u_input : bpy.props.StringProperty(name = "Input: ", default = "")
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
print(self.u_input)
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self, width = 450)
def menu_func(self, context):
self.layout.operator(SimpleOperator.bl_idname, text=SimpleOperator.bl_label)
# Register and add to the "object" menu (required to also use F3 search "Simple Object Operator" for quick access).
def register():
bpy.utils.register_class(SimpleOperator)
bpy.types.VIEW3D_MT_object.append(menu_func)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
bpy.types.VIEW3D_MT_object.remove(menu_func)
if __name__ == "__main__":
register()
But this only works with strings for some reason.