pydrivers problem

Hi I have problem with pydrivers,
full description in .blend
silnik_2.blend (3.0 MB)

I’m not sure about your exact problem. But there is a way to extend pydriver functionality to more than a single line of code. If you create a text file called “pydrivers.py” in your blend file, this creates a global variable ‘p’ that you can use in your pydriver line of code.

So I modified your pydriver line of code to look like this.

p.refreshGreenGear()

This causes blender to look for a function named “refreshGreenGear” in the pydrivers.py text file. NOTE: The final function must return a float value.


def returnGearValue (passedGearName):
    return ((b.Object.Get(passedGearName).RotY)*(18/math.pi))/(50.00/20.00)


def refreshGreenGear ():
    result = 0.0
    #Determine what gear to use based upon what frame we are on.
    curframe = b.Get('curframe')
    gearToUse = '1B'
    if (curframe >300):
        gearToUse = '2B'
    result = returnGearValue(gearToUse)
    return result

def refreshOrangeGear ():
    result = 0.0
    curframe = b.Get('curframe')
    gearToUse = 'ww'
    result = returnGearValue(gearToUse)
    return result

So this code will change the name of the gear from 1B to 2B after it passes frame 300. Perhaps you can come up with another way to change the name, but hopefully, this concept will open up the fact that you can do very complex things with pydrivers. (i.e. more than a single line). Also, you can put multiple functions in this single text file and make calls to different functions from different objects with pydrivers.

The orange gear does work for me when I paste your code into that object. However, you do have to actually select that object and then select the channel you want to affect, then add a pydriver to that channel. Perhaps you were just pasting the second line of code into the green gears pydriver by mistake (I did that initially).

thanks but it don’t work for me or I don’t know how to apply this function

could you post .blend file?

Yeah, I tried to reattach the BLEND file, but it is too big even after compression,sorry.:frowning:

Here is what I did. I took my working BLEND file and deleted all the objects in the 3D scene. This leaves only the new code in the BLEND file. Copy that file into your working scene and remember to name the new text file “pydrivers.py” or it will not work. Or better yet, use Blender’s file Append to append the text into your scene and you will be assured that the file is named correctly. Scriptlinks must be enabled also.

In your scene, select the green gear and replace your existing line of code in the pydriver with the single line function call mentioned above.

p.refreshGreenGear()
I used a pydriver in my recent Cubic Transition script and was able to leverage this technique.
I did a short walk though on setting up pydrivers in a video tutorial here: Scrub Ahead to 4:40.
http://vimeo.com/11762664

Attachments

pydriver_gears.blend (255 KB)

now I know, I forget to enable script links

thanks, I’m your debtorhttp://download1.klimacik.pl/e-gify.com/336.gif