File: scripttemplate_text_plugin.py

package info (click to toggle)
blender 2.49.2~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 89,664 kB
  • ctags: 113,718
  • sloc: ansic: 738,048; cpp: 231,960; python: 104,955; asm: 33,960; sh: 16,233; ml: 12,962; makefile: 4,477; perl: 3,474; fortran: 108; java: 8
file content (69 lines) | stat: -rw-r--r-- 1,625 bytes parent folder | download
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()