0
$\begingroup$

I create script , that script add object, now i create, a modifier , and i want to simulate “Swinging” but i can not understand how it can be done,does anyone know how I can do? :

bend = object.modifiers.new(name="bend", type='SIMPLE_DEFORM')
bend.deform_method = 'BEND'
###noob example:
bend.angle.driver_add("sin(frame/20)")
$\endgroup$

1 Answer 1

3
$\begingroup$

Consult docs or other questions on how to add a driver

Here is your "noob" code edited to add a driver. Select a mesh object and run script.

It so happens that the current context.scene.frame_current is known to the driver namespace as frame so no driver variable need be created.

import bpy
ob = bpy.context.object
bend = ob.modifiers.new(name="bend", type='SIMPLE_DEFORM')
bend.deform_method = 'BEND'

fcurve = bend.driver_add("angle")
driver = fcurve.driver
driver.expression = "sin(frame/20)"

Also remember that angles when scripting are natively in radians. 2 pi radians = 360 degrees. So at frame 20 the angle of bend will be sine of 1 radian (or around 57 degrees.) Use sin(radians(frame) / 20) if frame is expected as degrees.

$\endgroup$
5
  • $\begingroup$ scuse me batFinger, fcurve = bend.driver_add("angle"). and for get("angle")? i try but give me error $\endgroup$
    – Noob Cat
    Commented Mar 7, 2019 at 10:15
  • 1
    $\begingroup$ bend.angle or getattr(bend, "angle") From the driver try fcurve.evaluate(frame) but not sure if this will work as expected. $\endgroup$
    – batFINGER
    Commented Mar 7, 2019 at 11:42
  • $\begingroup$ im not sure, i try to put getattr(bend, "angle") in a function with update, 1 function create modifier and driver, then , the funcion(update) make parameter, but not , work.I do not know if it is appropriate to open a new question $\endgroup$
    – Noob Cat
    Commented Mar 7, 2019 at 13:11
  • 1
    $\begingroup$ IMO It's appropriate. $\endgroup$
    – batFINGER
    Commented Mar 7, 2019 at 13:15
  • $\begingroup$ 'float' object has no attribute 'driver'. error $\endgroup$
    – Noob Cat
    Commented Mar 8, 2019 at 11:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .