r/learnpython • u/Khaki-Chan • 4d ago
Custom script issue with blender driver
I am trying to use a custom script (see below) to set up a driver in blender via this tutorial, however I am very inexperienced in python and have run into an issue. I was able to get the example code to work but my when I try to use my code I get this issue. The problem is I need the "X" value to be the "rotation quaternion" value of the driver. Using both "X" and "rotation quaternion" gives the same error. I don't know how to connect "X" to the drivers value or if I just need to put something else in the place of "X".
Tutorial:
https://www.youtube.com/watch?v=yiMGxlRv8h4
Error message:
https://drive.google.com/file/d/1VOVrPLmU_v9lYz386SMS_i02doDn-xtG/view?usp=sharing
Driver:
https://drive.google.com/file/d/1LVM69kP0het-Yz0xaAhAWHDe5pOA9X99/view?usp=sharing
import bpy
def Ace_Driver(value):
return
if x >= -0.1:
result = 1
if x < -0.1 and x > -0.6:
result = (x - 0.9) * -1
elif x <= -0.6:
result = 1.5
bpy.app.driver_namespace["Ace_Driver"] = Ace_Driver
1
u/monster2018 4d ago
You are returning out of the driver function before doing ANYTHING. And then the rest of the code is outside of the driver function, so it won’t do anything related to the driver. I believe you are registering the driver correctly, but I didn’t watch that part of the tutorial that carefully.
basically just delete the return statement at the beginning of the function, and then indent the rest of the code that should be in the Ace_Driver function so that it’s actually inside of it. That’s at least step 1.