New add-on: IDE script executor #14
86
development_idee.py
Normal file
86
development_idee.py
Normal file
@ -0,0 +1,86 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
bl_info = {
|
||||
"name": "IDE script executor",
|
||||
"description": "Runs python scripts saved by IDE / external editor",
|
||||
"author": "Crisp Ness",
|
||||
"version": (0, 1),
|
||||
"blender": (3, 6, 0),
|
||||
"location": "Preferences > Add-ons",
|
||||
"warning": "",
|
||||
"doc_url": "https://projects.blender.org/Crisp-Ness/doc/src/branch/main/idee_0.1.md",
|
||||
"tracker_url": "https://projects.blender.org/Crisp-Ness/doc/issues",
|
||||
"support": "COMMUNITY",
|
||||
"category": "Development",
|
||||
}
|
||||
|
||||
from os import path, remove
|
||||
import bpy
|
||||
|
||||
|
||||
def idee_onerun():
|
||||
"""
|
||||
Checks for the existence of the path file.
|
||||
If found: reads path to script, removes path file, runs script.
|
||||
Returns timer delay for next run.
|
||||
"""
|
||||
prefs = bpy.context.preferences.addons[__name__].preferences
|
||||
|
||||
if not path.exists(prefs.pathfile):
|
||||
return prefs.delay
|
||||
|
||||
with open(prefs.pathfile) as pf:
|
||||
path_to_script = pf.read().strip()
|
||||
remove(prefs.pathfile)
|
||||
|
||||
try:
|
||||
bpy.utils.execfile(path_to_script)
|
||||
except BaseException:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
return prefs.delay
|
||||
|
||||
|
||||
class IdeePrefs(bpy.types.AddonPreferences):
|
||||
bl_idname = __name__
|
||||
|
||||
pathfile: bpy.props.StringProperty(
|
||||
name="Path file",
|
||||
description="File containing path to script",
|
||||
subtype='DIR_PATH',
|
||||
default="/tmp/idee.path",
|
||||
)
|
||||
delay: bpy.props.FloatProperty(
|
||||
name="Delay",
|
||||
description="Delay in seconds between consecutive runs",
|
||||
default=1.00,
|
||||
min=0.01,
|
||||
max=60.0,
|
||||
precision=2,
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
box = layout.box()
|
||||
box.row().prop(self, "pathfile")
|
||||
box.row().prop(self, "delay")
|
||||
|
||||
|
||||
def remove_pathfile():
|
||||
prefs = bpy.context.preferences.addons[__name__].preferences
|
||||
if path.exists(prefs.pathfile):
|
||||
remove(prefs.pathfile)
|
||||
|
||||
|
||||
def register():
|
||||
bpy.utils.register_class(IdeePrefs)
|
||||
remove_pathfile()
|
||||
bpy.app.timers.register(idee_onerun, persistent=True)
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.app.timers.unregister(idee_onerun)
|
||||
remove_pathfile()
|
||||
bpy.utils.unregister_class(IdeePrefs)
|
Reference in New Issue
Block a user