Created
July 29, 2015 08:03
-
-
Save zeffii/2b488961226ee1ecefcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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