Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pushpuller-addon.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import bpy
  2. class OBJECT_PT_pushpuller(bpy.types.Header):
  3. bl_label = "Push Puller"
  4. bl_space_type = "TEXT_EDITOR"
  5. bl_region_type = "HEADER"
  6. bl_context = "object"
  7. def draw_header(self, context):
  8. layout = self.layout
  9. layout.label(text="", icon="PHYSICS")
  10. def draw(self, context):
  11. layout = self.layout
  12. row = layout.row()
  13. split = row.split(percentage=0.5)
  14. col_left = split.column()
  15. col_right = split.column()
  16. col_right.operator("object.puller", text="Pull All")
  17. col_left.operator("object.pusher", text="Push All")
  18. class OBJECT_OT_pusher(bpy.types.Operator):
  19. bl_label = "Pusher"
  20. bl_idname = "object.pusher"
  21. bl_description = "Push text data block changes"
  22. def execute(self, context):
  23. area = bpy.context.area
  24. for text in bpy.data.texts:
  25. area.spaces[0].text = text
  26. if text.filepath != '' and text.is_dirty:
  27. bpy.ops.text.save()
  28. print("Saving: ", text.filepath)
  29. self.report({'INFO'}, "Performing push")
  30. return {'FINISHED'}
  31. class OBJECT_OT_pullerer(bpy.types.Operator):
  32. bl_label = "Puller"
  33. bl_idname = "object.puller"
  34. bl_description = "Pull text data block changes"
  35. def execute(self, context):
  36. area = bpy.context.area
  37. self.report({'INFO'}, "Performing pull")
  38. for text in bpy.data.texts:
  39. area.spaces[0].text = text
  40. if text.filepath != '':
  41. try:
  42. bpy.ops.text.reload()
  43. except:
  44. print("error reloading: ", text.filepath)
  45. if text.filepath != '' and text.is_dirty:
  46. bpy.ops.text.save()
  47. return {'FINISHED'}
  48. def register():
  49. bpy.utils.register_module(__name__)
  50. def unregister():
  51. bpy.utils.unregister_module(__name__)
  52. if __name__ == "__main__":
  53. register()