Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/operator_simple.py
Created May 20, 2015 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/3ab3325eb92474abb204 to your computer and use it in GitHub Desktop.
Save zeffii/3ab3325eb92474abb204 to your computer and use it in GitHub Desktop.
import bpy
class TEXT_Cycle_TextBlocks(bpy.types.Operator):
bl_idname = "text.cycle_textblocks"
bl_label = "switch text content of current viewer"
bl_options = {'REGISTER', 'UNDO'}
direction = bpy.props.IntProperty(default=-1)
def execute(self, context):
edit_text = bpy.context.edit_text
texts = bpy.data.texts
num_texts = len(texts)
def get_index_of_text(text_name):
for idx, text in enumerate(texts):
if text.name == text_name:
return idx
current_idx = get_index_of_text(edit_text.name)
new_idx = (current_idx + self.direction) % num_texts
context.space_data.text = texts[new_idx]
return {'FINISHED'}
def register():
bpy.utils.register_class(TEXT_Cycle_TextBlocks)
def unregister():
bpy.utils.unregister_class(TEXT_Cycle_TextBlocks)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment