~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to release/scripts/scripttemplate_mesh_edit.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!BPY
 
2
"""
 
3
Name: 'Mesh Editing'
 
4
Blender: 243
 
5
Group: 'ScriptTemplate'
 
6
Tooltip: 'Add a new text for editing a mesh'
 
7
"""
 
8
 
 
9
from Blender import Window
 
10
import bpy
 
11
 
 
12
script_data = \
 
13
'''#!BPY
 
14
"""
 
15
Name: 'My Mesh Script'
 
16
Blender: 243
 
17
Group: 'Mesh'
 
18
Tooltip: 'Put some useful info here'
 
19
"""
 
20
 
 
21
# Add a licence here if you wish to re-distribute, we recommend the GPL
 
22
 
 
23
from Blender import Scene, Mesh, Window, sys
 
24
import BPyMessages
 
25
import bpy
 
26
 
 
27
def my_mesh_util(me):
 
28
        # This function runs out of editmode with a mesh
 
29
        # error cases are alredy checked for
 
30
        
 
31
        # Remove these when writing your own tool
 
32
        print me.name
 
33
        print 'vert count', len(me.verts)
 
34
        print 'edge count', len(me.edges)
 
35
        print 'face count', len(me.faces)
 
36
        
 
37
        # Examples
 
38
        
 
39
        # Move selected verts on the x axis
 
40
        """
 
41
        for v in me.verts:
 
42
                if v.sel:
 
43
                        v.co.x += 1.0
 
44
        """
 
45
        
 
46
        # Shrink selected faces
 
47
        """
 
48
        for f in me.faces:
 
49
                if f.sel:
 
50
                        c = f.cent
 
51
                        for v in f:
 
52
                                v.co = (c+v.co)/2
 
53
        """
 
54
 
 
55
def main():
 
56
        
 
57
        # Gets the current scene, there can be many scenes in 1 blend file.
 
58
        sce = bpy.data.scenes.active
 
59
        
 
60
        # Get the active object, there can only ever be 1
 
61
        # and the active object is always the editmode object.
 
62
        ob_act = sce.objects.active
 
63
        
 
64
        if not ob_act or ob_act.type != 'Mesh':
 
65
                BPyMessages.Error_NoMeshActive()
 
66
                return 
 
67
        
 
68
        
 
69
        # Saves the editmode state and go's out of 
 
70
        # editmode if its enabled, we cant make
 
71
        # changes to the mesh data while in editmode.
 
72
        is_editmode = Window.EditMode()
 
73
        
 
74
        Window.WaitCursor(1)
 
75
        me = ob_act.getData(mesh=1) # old NMesh api is default
 
76
        t = sys.time()
 
77
        
 
78
        # Run the mesh editing function
 
79
        my_mesh_util(me)
 
80
        
 
81
        # Restore editmode if it was enabled
 
82
        if is_editmode: Window.EditMode(1)
 
83
        
 
84
        # Timing the script is a good way to be aware on any speed hits when scripting
 
85
        print 'My Script finished in %.2f seconds' % (sys.time()-t)
 
86
        Window.WaitCursor(0)
 
87
        
 
88
        
 
89
# This lets you can import the script without running it
 
90
if __name__ == '__main__':
 
91
        main()
 
92
'''
 
93
 
 
94
new_text = bpy.data.texts.new('mesh_template.py')
 
95
new_text.write(script_data)
 
96
bpy.data.texts.active = new_text
 
97
Window.RedrawAll()
 
 
b'\\ No newline at end of file'