new version of python doesn't like my old blender python scripts

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)

The version of Python you have on your system is irrelevant: since the change from Blender 2.4x to 2.5x, Blender has used its own internal Python, which is currently version 3.2. At the same time, the Blender Python API has undergone huge changes. Old scripts that worked with Blender 2.49 typically need to be completely rewritten to work with 2.63.

Best wishes,
Matthew

Thanks for the information. So it sounds like I have no choice but to get completely new scripts.

Or do you think this might be possible?

I could install the old Blender version 2.49. Does this use the system python then?
In which case I’d have to install an old version of python too (version 2.6.5 worked).

I’d have to keep the new version for all the programs that use it (most of them, it seems). Then somehow point blender 2.49 to the old python that it works with. Does this sound like a possible workaround, or should I give up now???

I’m fairly sure you can have more than one version of python installed on the system simultaneously.Just not sure how to point just blender to it, and not the rest of the programs…

Yes.

In which case I’d have to install an old version of python too (version 2.6.5 worked).

Not necessarily. I’d expect 2.7 to work in most cases, too. Remember, Blender 2.63 was trying to use Python 3.2, which is very different from 2.6: but 2.7 should be backwards compatible with scripts written for 2.6.

Best wishes,
Matthew

first:
check the download section at blender.org,
there are still the older versions of blender available and
get the 2.49 version from there. Then you can use
your older scripts (for blender before 2.5) with this.
If you use more than one blender-version,
then you might setup a short script to change (cd)
to the install-directory of the new blender-version
and start it from there ( like: ./blender -w ).

Same goes for blender of the 2.5x versions - there were
a lot of python-api changes from 2.50 to 2.59.

And with the newest version of blender 2.63 there is a hard break
again (most scripts of 2.60/2.61/2.62 work on each version) with
bmesh, what not even “breaks” the scripts it breaks the blend-files too
(if you dont know how to export/import your models …).

btw. the most confusing thing is to watch some tutorials and later
on notice the nice demonstration only works with a blender-version
you have not installed …
therefore keep an eye on what version you are using.

edit: forgot to note: newer blender-version come with their own python part - only the older 2.4x versions did use the system installed python and for those you need to install the old pre-3.0-python.

Hi,

Thanks for the advice. I have tried installing Blender 2.49 from blender.org. I also installed python 2.5 just in case. As a result, when I run python, it states version 2.5, so it seems to have successfully installed.

However, when I dpkg the deb file of 2.49 it complains that it can’t find python 2.5, and halts the install. I have tried setting the environment variable PYTHONPATH to point to the python 2.5 version. But still the blender install thinks python 2.5 isn’t installed.

I also tried using the tar.gz file of blender 2.49 but that installs an executable of blender that also can’t find python 2.5. Finally, I tried (unsucessfully) to build blender 2.49 from the source files in the hope that the final executable would see the installed python 2.5. But unfortunately the make fails in the subdirectories intern and extern due to missing files.

Does anyone have any ideas how I might be able to get Blender 2.49 to see the Python 2.5 directory?

Thanks a lot!

one question here

i tested SVN 46363
and ran an older script making meshes and i did not convert it to new Bmesh
and now it seems tob e running with no problems

so was there any cahnge done in 2.63 so taht it can run older script API for making meshes?

any doc on this new feature

thanks