Python API Example Code No Longer Works

Hi all,

I was playing around with constraints and discovered that the example code for constraints in the API no longer works.
http://www.zoo-logique.org/3D.Blender/scripts_python/API/

The line in question is:


myConstraint = tempObject.constraints[0]

This code produces an error in Blender 2.48a.

Through trial and error (ha-ha no-pun intended) I discovered that the getitem method does still work.


myConstraint = tempObject.constraints.__getitem__(0)

What’s the error? And do you get the same thing from the official API?

http://www.blender.org/documentation/248PythonDoc/Constraint-module.html


       from Blender import *

       ob = Object.Get('Cube')
       if len(ob.constraints) > 0:
               const = ob.constraints[0]
               if const.type == Constraint.Type.FLOOR:
                       offs = const[Constraint.Settings.OFFSET]

The check for length is really important, perhaps vital, depending on the error.

Hmm…

Not able to reproduce the error now. I am doing the length check.

My code links and unlinks objects from the scene on a frame by frame basis. Perhaps there is some problem with an object after it has become unlinked, then relinked to a scene.

Do you have any insight?

Do you remember what the error was? I’m not familiar with the code, so without that I can’t really help, sorry.

The other thing is if you get the error again/recall it then please post your code. Without being able to trace the execution flow it’ll be impossible to tell what the issue is for anyone that hasn’t seen it before.

Cheers,
Ian

I wonder if constraints fall out of scope when you unlink an object…?