Created
November 11, 2024 06:02
-
-
Save CGArtPython/2ebf1830f752fecc213509c68edf468c to your computer and use it in GitHub Desktop.
Code for the Extended tutorial video "Easily Create Driver Variables with Blender Python" ( https://www.skool.com/cgpython/classroom/e707bee7?md=b48bf615d1a5465fb6835c4a98d2aa8b )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
def add_icosphere(): | |
bpy.ops.mesh.primitive_ico_sphere_add() | |
return bpy.context.active_object | |
def add_empty(): | |
bpy.ops.object.empty_add() | |
return bpy.context.active_object | |
def set_up_driver(driver_fcurve_obj, target_obj): | |
driver_obj = driver_fcurve_obj.driver | |
my_var = driver_obj.variables.new() | |
my_var.name = "py_var2" | |
my_var.targets[0].id = target_obj | |
my_var.targets[0].data_path = "location.z" | |
driver_obj.expression = f"{my_var.name} * 0.5" | |
def main(): | |
ico_sphere_obj = add_icosphere() | |
empty_obj = add_empty() | |
driver_fcurve_objs = ico_sphere_obj.driver_add("location") | |
for driver_fcurve_obj in driver_fcurve_objs: | |
set_up_driver(driver_fcurve_obj, empty_obj) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment