blob: 4ae562736d3e91875edad16aa9979b85e4b9816b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!BPY
"""
Name: 'Text Plugin'
Blender: 246
Group: 'ScriptTemplate'
Tooltip: 'Add a new text for writing a text plugin'
"""
from Blender import Window
import bpy
script_data = \
'''#!BPY
"""
Name: 'My Plugin Script'
Blender: 246
Group: 'TextPlugin'
Shortcut: 'Ctrl+Alt+U'
Tooltip: 'Put some useful info here'
"""
# Add a licence here if you wish to re-distribute, we recommend the GPL
from Blender import Window, sys
import BPyTextPlugin, bpy
def my_script_util(txt):
# This function prints out statistical information about a script
desc = BPyTextPlugin.get_cached_descriptor(txt)
print '---------------------------------------'
print 'Script Name:', desc.name
print 'Classes:', len(desc.classes)
print ' ', desc.classes.keys()
print 'Functions:', len(desc.defs)
print ' ', desc.defs.keys()
print 'Variables:', len(desc.vars)
print ' ', desc.vars.keys()
def main():
# Gets the active text object, there can be many in one blend file.
txt = bpy.data.texts.active
# Silently return if the script has been run with no active text
if not txt:
return
# Text plug-ins should run quickly so we time it here
Window.WaitCursor(1)
t = sys.time()
# Run our utility function
my_script_util(txt)
# Timing the script is a good way to be aware on any speed hits when scripting
print 'Plugin script finished in %.2f seconds' % (sys.time()-t)
Window.WaitCursor(0)
# This lets you import the script without running it
if __name__ == '__main__':
main()
'''
new_text = bpy.data.texts.new('textplugin_template.py')
new_text.write(script_data)
bpy.data.texts.active = new_text
Window.RedrawAll()
|