It is probably (definitely) easier to do this via the Graph Editor but please bear in mind that I am starting out learning Python in Blender so it could end up being just a valuable learning experience rather than a better way of doing things.
I am trying to write a script that will create a cube and add a built in modifier - the default in the Graph Editor is a sine curve. The code below does that. However, I would like to change the Amplitude, Phase Multiplier, Phase Offset and Value Offset. And maybe even the curve type to something else - it would be good to know how.
Standard approach so far has been to copy code from the Info window and try in the Console. When I alter Amplitude in the Graph Editor, for example, the code generated is:
bpy.data.actions[āCubeAction.008ā].(null) = 10
This throws up a syntax error because .(null) is invalid when used in Console. Looking at the available options (by pressing TAB after ā].ā hasnāt helped.
Incidentally, it doesnāt matter what property I change in the Graph Editor, the .(null) thing pops up for all of them in the Info window which is very odd.
Iāve tried using several options. Iāve tried putting that line after the ui_type change in the Text Editor just incase it was down to a context error but that did not work.
After two hours and several cups of tea Iāve come to you chaps for help
#090522
#Creates cube, adds keyframe, changes ui.type to add built in sine curve in graph editor
import bpy
bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align=āWORLDā, location=(0, 0, 0), scale=(1, 1, 1))
mycube = bpy.data.objects[0]
mycube.keyframe_insert(data_path = ālocationā, frame = 1)
bpy.context.area.ui_type = āFCURVESā
bpy.ops.graph.fmodifier_add(type=āFNGENERATORā, only_active=True)
bpy.context.area.ui_type = āTEXT_EDITORā
PS:
I have been messing with the following line from sozap who helped with an answer to an earlier question. But Iām not making progress not matter how I modify it
bpy.context.selected_objects[0].animation_data.action.fcurves[0].data_path