File: scripttemplate_metaball_create.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 (76 lines) | stat: -rw-r--r-- 1,773 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
70
71
72
73
74
75
76
#!BPY
"""
Name: 'Metaball Generation'
Blender: 245
Group: 'ScriptTemplate'
Tooltip: 'Script template to make metaballs from a mesh'
"""

from Blender import Window
import bpy

script_data = \
'''#!BPY
"""
Name: 'My Metaball Script'
Blender: 245
Group: 'Misc'
Tooltip: 'Put some useful info here'
"""

# Add a license here if you wish to re-disribute, we recommend the GPL

from Blender import Metaball, Mesh, Window
import bpy

def makeMetaSculpture(sce):
    #Create a base mesh for our sculpture to use
    monkey = Mesh.Primitives.Monkey()
    
    #Create a new meta datablock to use and give it a name
    metaObj = Metaball.New()
    metaObj.name = "MetaSuzanne"
    
    #Increase the resolution so it looks better
    metaObj.wiresize = 0.2
    metaObj.rendersize = 0.1
    
    #The radius for our new meta objects to take
    metaRadius = 2.0
    
    for f in monkey.faces:
        
        #Create a new metaball as part of the Meta Object Data
        newBall = metaObj.elements.add()
        
        #Make the new ball have the same coordinates as a vertex on our Mesh
        newBall.co = f.cent
        
        #Assign the same radius to all balls
        newBall.radius = f.area * metaRadius
    
    #Create the new object and put our meta data there
    sce.objects.new(metaObj, "MetaSuzanne")
        

def main():
    scene = bpy.data.scenes.active #Get the active scene
    
    Window.WaitCursor(1)
    
    #Call the sculpture making function
    makeMetaSculpture(scene)
    
    Window.WaitCursor(0)
    
    #Redraw the Screen When Finished
    Window.RedrawAll(1)

if __name__ == '__main__':
    main() 
'''

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