# How can a parameter be passed from one operator to another?

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):

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


AttributeError: 'OBJECT_OT_anim_operator' object has no attribute 'text_name'

• The snippet actually seems to work. pasteall.org/52716/python – pink vertex Jul 9 '14 at 13:12
• I don't know very much about Blender scripting, but I do know a bit of Python. I don't see "OBJECT_OT_anim_operator" anywhere in your code; the example you linked to defined a similarly named class. In both of your classes, the variable txt is 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. – ksoo Jul 11 '14 at 14:58

I had to add the self keyword to access the variable in the invoked operator (basic python, ouch!)

class AnimOperator(bpy.types.Operator):
bl_idname = "object.anim_operator"
bl_label = "Pose Anim Operator"

text_name = bpy.props.StringProperty(name="anim_text_name")
@classmethod
def poll(cls, context):
return context.active_object is not None

def execute(self, context):
print("invoked script name=%s" % self.text_name ) # <<- self.