Very basic problem with bylink

Hi all,

I’m just starting to get into Python scripting in blender, and I’ve already hit a weird snag. When I try to execute this example code from Wartmann’s “The Blender Book” (which, true, is not up to date for my version 2.25 blender):


import Blender
if (Blender.bylink):
     obj = Blender.link
     if (obj.LocZ <0.0): obj.LocZ = 0.0

For some reason, it doesn’t work at all. It seems as if the object I’ve linked to the script isn’t acknowledging the link. The script is supposed to prevent an object from going lower than 0 on the Z axis.

I’ve tried linking with Frames Changes as well as Redraw, but no dice. I can get it to send info to stdout by including this line:

print Blender.bylink

Naturally, all it outputs is 0 everytime I move the object around. Has anyone else run into this? It’s seems really, really basic, but I can’t find any documentation of the problem.

As long as you have linked to the object (buttons on the left side of the scriptlinks screen after you clicked the arrows button in the header), it should work. However, when there were syntax or other errors in the script, then it appears that the script isn’t updated internally or something and so doesn’t work any longer, the only solution seems to be a restart. Another 2.25 bug I guess…

Oh, goody, I thought it was only me. This is quite an annoying bug.

:frowning: Huh? I was about to enter the exact same code example with the exact same problem. No need to - BUT I don’t understand the response. What arrow keys? My script buttons are
on the right. Can you be more specific?

Not arrow keys, but arrow button. You have to select the object first that you want to link with a script, then you will see that button in the header bar of the script buttons section. When you click that, a new set of buttons will appear on the LEFT, there is where you link the actual script. Right side is for a global script, not linked to a specific object, left side is for other types of scriptlinks. As you can see in the picture, there is a button to scriptlink to a material too (the red sphere).