Welcome to mirror list, hosted at ThFree Co, Russian Federation.

scripttemplate_object_edit.py « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4f8e0bccfa2352d39b251a9ef3c0a20c7bbc2e41 (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
70
71
72
73
74
75
76
77
78
79
80
81
#!BPY
"""
Name: 'Object Editing'
Blender: 243
Group: 'ScriptTemplate'
Tooltip: 'Add a new text for editing selected objects'
"""

from Blender import Window
import bpy

script_data = \
'''#!BPY
"""
Name: 'My Object Script'
Blender: 244
Group: 'Object'
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 bpy

def my_object_util(sce):
	
	# Remove these when writing your own tool
	print 'Blend object count', len(bpy.data.objects)
	print 'Scene object count', len(sce.objects)
	
	# context means its selected, in the view layer and not hidden.
	print 'Scene context count', len(sce.objects.context)
	
	# Examples
	
	# Move context objects on the x axis
	"""
	for ob in sce.objects.context:
		ob.LocX += 1
	"""
	
	# Copy Objects, does not copy object data
	"""
	# Store the current contetx
	context = list(sce.objects.context)
	# de-select all
	sce.objects.selected = []
	
	for ob in context:
		ob_copy = ob.copy()
		sce.objects.link(ob_copy)	# the copy is not added to a scene
		ob_copy.sel = True
	"""

def main():
	
	# Gets the current scene, there can be many scenes in 1 blend file.
	sce = bpy.data.scenes.active
	
	Window.WaitCursor(1)
	t = sys.time()
	
	# Run the object editing function
	my_object_util(sce)
	
	# Timing the script is a good way to be aware on any speed hits when scripting
	print 'My Script finished in %.2f seconds' % (sys.time()-t)
	Window.WaitCursor(0)
	
	
# This lets you can import the script without running it
if __name__ == '__main__':
	main()

'''

new_text = bpy.data.texts.new('object_template.py')
new_text.write(script_data)
bpy.data.texts.active = new_text
Window.RedrawAll()