Is it possible to use the select_pattern() function for user input?

Good morning!
I am a student trying to develop a Blender add-on for automating an optimization workflow. My knowledge about Python and programming in general is limited.

My question is about the select_pattern() function (https://docs.blender.org/api/current/bpy.ops.object.html).

I am currently working on an UI Panel where I would like the user to be able to enter a name in a dialog box and this name is then put through the select_pattern function. As of now, this works, but only if the user inputs the exact name of the object. I know that with * and " ", filters can be applied to the select_pattern function and this works perfectly in my experience.

So right now, if the user would like to search for the Object “TestCube”, it would only work if the user inputs that exact name.
If I would manually use the select_pattern function, I could for example say:
bpy.ops.object.select_pattern(pattern=“* test *”)

However, this would be hard-coded. I would love for the variable of the user input to be used in this function, best would be if the filters could still be applied. Is this possible?

Here is a screenshot of my code:

This is how the UI panel looks:
image

Thank you in advance!

The below change should work for you.

bpy.ops.object.select_pattern(pattern=f"*{t}*")

As a recommendation for future posts I would suggest posting code in the code block </> symbol to make it easier for people to read and if needed copy.

Thank you so much, this works perfectly! Does the f mean format?

And good point, I will keep it in mind! :slight_smile:

Used for evaluation of items in braces. I think it was part of python 3.0 but could be wrong.

Python f-String Tutorial – String Formatting in Python Explained with Code Examples (freecodecamp.org)

Awesome, I did not know about this! Thank you! :slight_smile: