3
$\begingroup$

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.

$\endgroup$
5
  • 1
    $\begingroup$ Try from drivers import driver_Combo in the py console. $\endgroup$ Commented Jan 14, 2017 at 12:33
  • $\begingroup$ 100%. Make that an answer and I'll accept your solution. Thank you very much. $\endgroup$ Commented Jan 14, 2017 at 12:40
  • $\begingroup$ A beautiful example of: "Blender: You'll get it when you get it." Going from W.T.F. ?? annoyance, lots of searching that offers no help, mild-headache to Lights On - Ah Ha ! $\endgroup$ Commented Jan 14, 2017 at 12:45
  • $\begingroup$ Yes it's like that. $\endgroup$ Commented Jan 14, 2017 at 12:53
  • 1
    $\begingroup$ This may interest you. $\endgroup$ Commented Jan 14, 2017 at 18:34

1 Answer 1

1
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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 blender.stackexchange.com/a/51078/34249 $\endgroup$ Commented Jan 18, 2017 at 15:03

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.