Names, user strings, variables and UI's

Hi Guys can anyone point me towards a tutorial or explain how to use python to Create a User input text field that populates a variable

For instance If the user entered “example” in to the text field, then the variable MyVar = “example”
so that I could access the string with the rest of my script. Specifically so I can rename objects.

I’ve searched but perhaps I’m searching for the wrong things…

Created a little demo:

import bpy

class PrintSomeString(bpy.types.Operator):
    bl_label = "Print Some String"
    bl_idname = "object.print_some_string"
    bl_options = {'REGISTER', 'UNDO'}
    
    print_this = bpy.props.StringProperty(name="Print this")
    
    def execute(self, context):
        self.report({'INFO'}, self.print_this)
        return {'FINISHED'}
        

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout
        layout.prop(context.window_manager, "some_string")
        
        props = layout.operator(PrintSomeString.bl_idname)
        props.print_this = context.window_manager.some_string

        props = layout.operator(PrintSomeString.bl_idname, text="Print welcome message")
        props.print_this = "Welcome to Blender!"

def register():
    bpy.utils.register_module(__name__)
    bpy.types.WindowManager.some_string = bpy.props.StringProperty(name="Some String")


def unregister():
    bpy.utils.unregister_module(__name__)
    del bpy.types.WindowManager.some_string


if __name__ == "__main__":
    register()



Thank you SO much for taking the time to do that for me codeman! I’ll Take a look at that in blender and see how i get on :smiley:

Just been through the code. Its perfect for what I needed, thank you so much for taking the time to help. :slight_smile:

you’re welcome :slight_smile:

such basic examples should really be added to the api docs, there might be similar ones on the wiki, but they are hard to discover