Can we parse "string" as Driver Variable? I am using scripted driver to changes image texture.

import bpy

def change_image_baby( val,min,max):
    if (min &lt;= val &lt;= max):
        filePath = "//baby_eyes\\eye_0%d.png" % val
        bpy.data.images["Minu Child eyes.001"].filepath = filePath
    return val

bpy.app.driver_namespace['change_image_baby'] = change_image_baby


On bone Movement by using above function as driver I am able to change the images.

Now i want to use same driver function on many other characters.

So I defined "filePath" and "image" name as object property of each character



New driver function

import bpy

def change_image(n,min,max,img,file):
    val = int(n*10)
    # img is image to be replaced and "file" is the file path
    return val
    if (min &lt;= val &lt;= max):
        filePath = file % val # as all my images are in sequence i replacing numbers see above code
        bpy.data.images[img].filepath = filePath

bpy.app.driver_namespace['change_image'] = change_image


and use in driver UI to parse it to custom driver


I am not able to parse string it has to be either int or float. What is the workaround to parse string as Driver Variable?
in this method we try to identify the object that is running the driver then we access its properties ( image and file ):


we add a new property to all scene objects this property is their index in the scene objects list ( we need to run this every time we add/delete an object to the scene ) :

import bpy
for obj in bpy.context.scene.objects :
    obj["index"] = bpy.context.scene.objects.find(obj.name)

we pass only the object index to the driver to identify it and access its properties.

import bpy

def change_image(n,min,max,index):
    obj = bpy.context.scene.objects[index]
    val = int(n*10)
    if (min &lt;= val &lt;= max):
        filePath = obj["file"] % val 
        bpy.data.images[obj["img"]].filepath = filePath

bpy.app.driver_namespace['change_image'] = change_image