Hi,
I have some old python scripts that worked fine until I recently updated my version of Ubuntu. With the new updated version of Python (now version 2.7.3) and blender (version 2.63), it complains about the old scripts when I try and run them in blender. Originally they worked fine on python 2.6.5.
I don’t know python myself (i was given the scripts as a present). I was hoping that someone might be able to take a look at one of them and tell me how/if they could be updated to work with python version 2.7.3.
I have (optimistically!) pasted them below this message. They are not long and (I would guess) fairly simple for someone who knows Python. They are called 1) Gas Animation.py, 2) Trajectories.py
When I run Gas Animation.py in blender it first complains about:
>print obn
which I believe can be easily fixed to:
>print(obn)
It then complains about:
>import Blender as B
>from Blender import *
>from Blender.BGL import *
>from Blender.Draw import *
>from Blender.Noise import *
>from Blender.Mathutils import Rand
I’m not sure what the new syntax should be for this bit.
I also don’t know if there are other bits of the scripts that won’t be easily fixed just by changing the syntax.
I would really appreciate it if someone could take a quick look at the scripts below, and see what they think might be possible to get them working again with an up-to-date blender (v 2.63) and python (v 2.7.3). They previously worked on blender compiled with python 2.6.5.
Thanks a lot
Gas Animation.py:
ANIMATED OBJECTS SCRIPT
Imports x,y,z positions as points in meshes in a cunning way so as to look
animated
20000 particles over 10 frames ~ 20 seconds
Can set start frame and number of frames to read in
Imports to active layer
import Blender as B
from Blender import *
from Blender.BGL import *
from Blender.Draw import *
from Blender.Noise import *
from Blender.Mathutils import Rand
s = Create(0)
Textbox3 = Create(’ Input filename’)
nf = Create(0)
np = Create(0)
def draw():
global s, Textbox3, Button1, nf, np
glClearColor(0.753, 0.753, 0.753, 0.0)
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.000, 0.000, 0.000)
glRasterPos2i(104, 162)
Text(' Start frame')
glColor3f(0.000, 0.000, 0.000)
glRasterPos2i(104, 132)
Text(' No. frames')
glRasterPos2i(104, 188)
Text(' No. particles')
glRasterPos2i(24, 264)
Text('Animates a series of particles from the input text file. File format x,y,z.')
Button('Go !', 1, 24, 80, 151, 31, '')
Textbox3 = String('', 2, 24, 208, 150, 23, Textbox3.val, 399, '')
s = Number('', 3, 24, 152, 71, 20, s.val, 1, 10000, '')
nf = Number('', 4, 24, 123, 71, 20, nf.val, 1, 10000, '')
np = Number('', 5, 24, 179, 71, 20, np.val, 1, 150000, '')
def create_mesh( infile, obn ):
global nf
global np
scn=B.Scene.GetCurrent()
ob=B.Object.New(‘Mesh’,‘Meshob’)
me=B.Mesh.New(‘myMesh’)
for i in range(1,np.val+1):
line = infile.readline()
x,y,z = line.split()
p=[float(x),float(y),float(z)]
me.verts.extend(float(x),float(y),float(z))
ob=scn.objects.new(me,'Gas')
ipo = Ipo.New('Object', 'ObIpo')
curve = ipo.addCurve('LocX')
curve.addBezier( ((obn-1)+s.val,-20000) )
curve.addBezier( (obn+s.val,0) )
curve.addBezier( ((obn+1)+s.val,-20000) )
curve.update()
ob.setIpo(ipo)
def event(evt, val):
if (evt== QKEY and not val): Exit()
def bevent(evt):
if evt == 1:
infile=open(Textbox3.val,‘r’)
for f in range(1,s.val):
for j in range(1,np.val+1): # Skips first s-1 lines. Starts doing stuff on frame s.
line = infile.readline()
for obn in range(1,nf.val+1):
create_mesh( infile, obn )
print obn
Exit()
B.Redraw()
Register(draw, event, bevent)
Trajectories.py:
PARTICLE TRAJECTORY SCRIPT
Reads in x,y,z from a file and draws a line on the selected layer.
Simulatenously animates an Empty for camera tracking.
Designed for positions of a single object over multiple frames.
File columns should be x,y,z
By default, camera and empty are on layer 11. Path will be created on active layer.
Camera is already parented and tracking empty
import Blender as B
from Blender import *
from Blender.BGL import *
from Blender.Draw import *
from Blender.Noise import *
s = Create(0)
Textbox3 = Create(’ Input filename’)
n = Create(0)
def draw():
global s, Textbox3, Button1, n
glClearColor(0.753, 0.753, 0.753, 0.0)
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.000, 0.000, 0.000)
glRasterPos2i(104, 162)
Text(' Start frame')
glRasterPos2i(104, 132)
Text(' No. frames')
glRasterPos2i(24, 240)
Text('Animates a series of particles from the input text file. File format x,y,z.')
Button('Go !', 1, 24, 80, 151, 31, '')
Textbox3 = String('', 2, 24, 184, 150, 23, Textbox3.val, 399, '')
s = Number('', 3, 24, 152, 71, 20, s.val, 1, 1000, '')
n = Number('', 4, 24, 123, 71, 20, n.val, 1, 1000, '')
def plot( line, me, i, object ):
frame=B.Get('curframe')
frame=frame+1
B.Set("curframe",frame)
x,y,z = line.split()
verts = [float(x),float(y),float(z)]
me.verts.extend(float(x),float(y),float(z))
edges = [i-1,i]
me.edges.extend( edges )
object.setLocation(float(x), float(y), float(z))
object.insertIpoKey(B.Object.LOC)
def event(evt, val):
if (evt== QKEY and not val): Exit()
def bevent(evt):
if evt == 1: #Button1
infile=open(Textbox3.val,‘r’)
scn=B.Scene.GetCurrent()
ob=B.Object.New('Mesh','Meshob')
me=B.Mesh.New('myMesh')
B.Set("curframe",1) # Sets initial frame to 1.
object=B.Object.Get('Empty')
for f in range(1,s.val): # Skips first s-1 lines. Starts doing stuff on frame s.
line = infile.readline()
B.Set("curframe",s.val) # Starts on frame s.
line = infile.readline() # Creates initial conditions. Could do this within loop ?
x,y,z =line.split() # Line split - change if needed
verts=[float(x),float(y),float(z)]
me.verts.extend(float(x),float(y),float(z))
object.setLocation(float(x), float(y), float(z))
object.insertIpoKey(B.Object.LOC)
frame=B.Get('curframe')
for i in range(1,n.val+1):
line = infile.readline()
plot(line, me, i, object)
ob.link(me)
ob=scn.objects.new(me,'Path')
infile.close()
B.Set("curframe",1)
Exit()
B.Redraw()
Register(draw, event, bevent)