3

Summary - Background

  • Created a text drivers.py file in Gedit
  • Opened drivers.py in Blender Text Editor
  • Selected [x] Register

Summary - Issue

  • The scripts are available to my scaling drivers

    • No problem there
  • When I try to run a test value in the python console I get the error

    • NameError: name 'driver_Combo' is not defined

Summary - Question

Do I need to do something to make the (external) scripts available in the Python Console ?

Full Details

Just recently started learning Blender.

I am using driver scripted expressions for [ Transform ] [ Scale ] of objects.

I was creating (and testing) scripts in the Python Console:

  • all good with achieving my driver scaling
  • scripts created in Python Console were not being saved with my .blend

Now I have moved them into the text editor:

  • Created a text drivers.py file in Gedit
  • Opened drivers.py in Blender Text Editor
  • Selected [x] Register

This is the content of drivers.py

import bpy  
from math import degrees, radians  
from math import pi  
from math import sin  

# def function 
def driver_Combo(time):  
   radius = max(abs(sin(radians(time))),abs(sin(radians(time+90))))  
   if time > 360:  
      radius = 0  
   return radius  

# add function to driver_namespace 
bpy.app.driver_namespace['driver_Combo'] = driver_Combo

I'd like to have the scripts available in the Python Console to test values.

How do I make the scripts available ?

Thanks.

TaoRich
  • 187
  • 1
  • 8

1 Answers1

1

All good, you have the file "drivers.py" (correctly with the py extension) registered already you can simply

import drivers
drivers.driver_Combo(..

or

from drivers import driver_Combo

in the py console

batFINGER
  • 84,216
  • 10
  • 108
  • 233
  • Thanks. For any other users who arrive here searching for the same issue, check out this answer for a great way to simply run a bunch of import or other statements in a startup file - for example - OnLoad.py: 2 or 3 line text-block http://blender.stackexchange.com/a/51078/34249 – TaoRich Jan 18 '17 at 15:03