# Text input field panel add-on blender 2.8

I am integrating a database in Blender. For this, I want to use text input fields. But at the moment I can't edit these fields. And I can't figure out whats wrong with it.

The code used for this is:

class SelectByQuery(bpy.types.Operator):

bl_idname = "object.select_by_query"
bl_label = "Selection of object by query"

query: bpy.props.StringProperty(default="testtest")

def execute(self, context):
try:
bpy.data.objects[self.query].select_set(True)
return {'FINISHED'}
except:
print('Could not select object')
return {'CANCELLED'}
class PanelThree(View3DPanel, bpy.types.Panel):
bl_idname = "VIEW3D_PT_SelectionQuery"
bl_label = "Selection Query"

def draw(self, context):
layout = self.layout

col = layout.column(align=True)
rowsub = col.row(align=True)

rowsub.label(text="SELECT *")

rowsub = col.row(align=True)
col2 = layout.column()
rowsub2 = col2.row()
props = rowsub2.operator("object.select_by_query", text="Query")
rowsub.prop(props, "query", text="")


I was able to add a default text and print the text by editting the SelectByQuery but I can't seem to make it that the user can edit the text.

• Not at my PC, the problem as far as I can tell is that you didn't declare your property in the right way not sure through it has been a while since I coded in Python with the blender api, I might take a look later shouldn't be to difficult to get it working. – Syler May 13 '19 at 16:06
• Check out bpy.ops.object.select_pattern() It pops up a modal dialog with input box for the pattern. – batFINGER May 13 '19 at 17:48
• @batFINGER It is connected with a database in the background the SelectByQuery is not done yet this was just to get the UI working – Gijs Schrijver May 13 '19 at 21:18
• @Syler if you could take a look that would be a great help already – Gijs Schrijver May 14 '19 at 10:56
• What you are trying to re have operator prop in general panel UI does not work, and has been answered before. Need a string property on say the window manager, and pass its value to the operator properties. IMO would do this with a string property and associated update method. The select pattern operator, or other registered operators set operator properties in the modal popup, or the active operator popup (or panel in < 2.8), where the operator is passed as self in the layout.prop(self, "foo"), the operator properties object from prop = layout.operator("foo.bar") – batFINGER May 14 '19 at 14:27

As i mentioned you declared the prop in the wrong way here is an example of how you could do what you want.

just copy and paste the code in the blender script editor and click the register checkbox (im not sure if you have to do that) then click run script, now if you go to the object tab in the properties area at the bottom you should have a Selection query panel, you can type bpy.context.scene.QueryProps.query in the console that should give you the current value for the query property, changing the property in the panel will change the property value to what you typed in.

import bpy

class QueryProps(bpy.types.PropertyGroup):

query: bpy.props.StringProperty(default="testtest")

class SelectByQuery(bpy.types.Operator):

bl_idname = "object.select_by_query"
bl_label = "Selection of object by query"

def execute(self, context):
try:
bpy.data.objects[self.query].select_set(True)
return {'FINISHED'}
except:
print('Could not select object')
return {'CANCELLED'}

class PanelThree(bpy.types.Panel):
bl_idname = "VIEW3D_PT_SelectionQuery"
bl_label = "Selection Query"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'

def draw(self, context):
props = bpy.context.scene.QueryProps
layout = self.layout

col = layout.column(align=True)
rowsub = col.row(align=True)

rowsub.label(text="SELECT *")

rowsub = col.row(align=True)
col2 = layout.column()
rowsub2 = col2.row()
rowsub2.operator("object.select_by_query", text="Query")
rowsub.prop(props, "query", text="")

classes = (
QueryProps,
SelectByQuery,
PanelThree
)

def register():

from bpy.utils import register_class
for cls in classes:
register_class(cls)
# Register QueryProps
bpy.types.Scene.QueryProps = bpy.props.PointerProperty(type=QueryProps)

def unregister():

from bpy.utils import unregister_class
for cls in classes:
unregister_class(cls)
# \$ delete QueryProps on unregister
del(bpy.types.Scene.QueryProps)

if __name__ == "__main__":
register()


also don't forget to mark the question as answered if it answered your question, if you have any question about the answer feel free to write a comment.