0
$\begingroup$

how I can have a text block selection box in my add-on panel.

$\endgroup$
1
  • $\begingroup$ A few more details would help people answering immensely $\endgroup$
    – J Sargent
    Jan 11, 2018 at 23:54

2 Answers 2

0
$\begingroup$

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()   
$\endgroup$
1
  • $\begingroup$ Some explanation of the code would be useful, I think. $\endgroup$ Jan 12, 2018 at 11:38
0
$\begingroup$

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

More Details Here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .