how I can have a text block selection box in my add-on panel.
Asked
Active
Viewed 273 times
2 Answers
0
PointerProperty that points to a text.
@Community popped this q up not long after I answered How to make a Text File dependent of an Armature object so that it appends with it to other projects?
A text block can be asscociated with another object or scene. Rather than selecting from all texts in file can be narrowed down by polling, and some code run when updated.
Script from link above.
import bpy
class OBJECT_PT_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"
#poll for armature object
@classmethod
def poll(cls, context):
return context.object and context.object.type == 'ARMATURE'
def draw(self, context):
layout = self.layout
arm_ob = context.object
layout.prop(arm_ob, "rig_script")
def is_armature_object(self, object):
return self.type == 'ARMATURE'
def register():
bpy.utils.register_module(__name__)
bpy.types.Object.rig_script = bpy.props.PointerProperty(
type=bpy.types.Text,
poll=is_armature_object,
)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Object.rig_script
if __name__ == "__main__":
register()
Links
batFINGER
- 84,216
- 10
- 108
- 233
0
this is the solution code that will make script search box.
import bpy
class OBJECT_PT_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
scene = context.scene
layout.prop_search(scene, "Script", bpy.data, "texts")
def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.Script = bpy.props.StringProperty()
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Scene.Script
if __name__ == "__main__":
register()
Fred
- 126
- 7