OK, after 4 hours of messing around starting to get a little frustrated. I’m trying to create a prop_search that list the names of logic sensors. I’ve been able to get a blank prop_search box to show up in the panel ,but I can’t figure out how to get the sensor names to show up. I found a sample code, that I’ve been playing with and it does what I want, but I need this to work in a panel and not a pop up. How do I do that.
Here’s the sample code that makes a pop up.
import bpy
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
bl_options = {'REGISTER', 'UNDO'}
sensors = bpy.props.StringProperty(name="Sensor 1", maxlen=63)
sensor_names = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)
def execute(self, context):
print(self.prop)
return {'FINISHED'}
def draw(self, context):
layout = self.layout
layout.prop_search(self, "sensors", self, "sensor_names", icon='LOGIC')
def invoke(self, context, event):
act_obj = bpy.context.active_object
for i in act_obj.game.sensors:
name = i.name
self.sensor_names.add().name = "%s" % name
return context.window_manager.invoke_props_dialog(self)
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.simple_operator('INVOKE_DEFAULT')