I used a python template to create a menu which is populated by the names of files from the text editor:
class AnimMenu(bpy.types.Menu):
bl_label = "Anim Menu"
bl_idname = "OBJECT_MT_anim_menu"
def draw(self, context):
layout = self.layout
for txt in bpy.data.texts:
if txt.name[-4:] =='.txt':
layout.operator("object.anim_operator", text=txt.name).text_name = txt.name # from here
Another operator should receive the filename as a parameter
class AnimOperator(bpy.types.Operator):
bl_idname = "object.anim_operator"
bl_label = "Pose Anim Operator"
text_name = bpy.props.StringProperty(name="anim_text_name") # to there
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
txt = bpy.data.texts[ text ].as_string()
main(context, text_name)
return {'FINISHED'}
I wasn't able to use this technique: How to set multiple custom attributes to operator class when called in UI layout?
props = layout.operator("object.anim_operator", text=txt.name)
props.text_name = txt.name
leads to:
AttributeError: 'OBJECT_OT_anim_operator' object has no attribute 'text_name'
txtis initialized only in a method within the class. I'm a bit rusty when it comes to coding, though, so perhaps this is all fine. – Stan Jul 11 '14 at 14:58