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$
2
$\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$
  • $\begingroup$ scuse me batFinger, fcurve = bend.driver_add("angle"). and for get("angle")? i try but give me error $\endgroup$ – Pastrokkio Mar 7 at 10:15
  • $\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 Mar 7 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$ – Pastrokkio Mar 7 at 13:11
  • 1
    $\begingroup$ IMO It's appropriate. $\endgroup$ – batFINGER Mar 7 at 13:15
  • $\begingroup$ 'float' object has no attribute 'driver'. error $\endgroup$ – Pastrokkio Mar 8 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.