Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created July 29, 2015 08:03
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/2b488961226ee1ecefcf to your computer and use it in GitHub Desktop.
Save zeffii/2b488961226ee1ecefcf to your computer and use it in GitHub Desktop.
import bpy
bl_info = {
"name": "quick script runner",
"author": "zeffii",
"version": (0, 1, 0),
"blender": (2, 7, 5),
"location": "3d view, sidebar (right)",
"category": "3D View"
}
'''
# test file
import bpy
import random
x = random.randint(-6, 6)
y = random.randint(-6, 6)
z = random.randint(-6, 6)
bpy.ops.mesh.primitive_cube_add(radius=1, location=(x, y, z),)
'''
class GlobalScriptRunner(bpy.types.Operator):
bl_idname = "view3d.global_script_runner"
bl_label = "Global Script Runner"
def execute(self, context):
textblock_name = context.scene.global_script_to_run
textblock = bpy.data.texts.get(textblock_name)
if textblock:
textblock_as_string = textblock.as_string()
exec(textblock_as_string)
return {'FINISHED'}
else:
return {'CANCELLED'}
class ScriptRunnerPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Script Runner"
bl_idname = "SCENE_PT_script_runner"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
# bl_context = "object"
def draw(self, context):
layout = self.layout
layout.label('script to run from shortcut')
layout.prop_search(context.scene, "global_script_to_run", bpy.data, "texts")
def register():
bpy.types.Scene.global_script_to_run = bpy.props.StringProperty()
bpy.utils.register_class(GlobalScriptRunner)
bpy.utils.register_class(ScriptRunnerPanel)
def unregister():
bpy.utils.unregister_class(GlobalScriptRunner)
bpy.utils.unregister_class(ScriptRunnerPanel)
del bpy.types.Scene.global_script_to_run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment