I've been able to assign an fcurve modifier to to fcurves in my scripts, but I can't figure out how to modify them once created.
here's what the info panel spits out when I do it manually:
bpy.ops.graph.fmodifier_add(type='LIMITS') #creates fcurve mod
bpy.data.node_groups["Shader Nodetree"].(null) = True #"maximum y" set to true
bpy.data.node_groups["Shader Nodetree"].(null) = 0 #"maximum y" value set to 0
bpy.data.node_groups["Shader Nodetree"].(null) = True #"use influence" set to true
bpy.data.node_groups["Shader Nodetree"].(null) = 0.5 #"use influence" set to 0.5
clearly this won't work in a script as is. what is the correct syntax for what I am doing?
EDIT:
I tried using zeffii's code, but I get an error from this line.
fcurve = ob.animation_data.action.fcurves[0]
error:
AttributeError: 'NoneType' object has no attribute 'action'
here is my code in it's entirety:
import bpy
import bmesh
import pprint
for i in range(1):
bpy.ops.mesh.primitive_cube_add(radius=1, view_align=False, enter_editmode=False, location=(i-5,0,0))
ob = bpy.context.active_object
#sets origin to bottom of object
bpy.context.scene.cursor_location = ob.location
bpy.context.scene.cursor_location.y -= 1
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
ob.scale = (0.5, 1.0, 0.5)
mat = bpy.data.materials.new(str(ob.name) + "mat")
mat.diffuse_color = (1,0,0)
mat.use_nodes = True
nodes = mat.node_tree.nodes
# clear all nodes to start clean
for node in nodes:
nodes.remove(node)
# create emission node
node_emission = nodes.new(type='ShaderNodeEmission')
node_emission.inputs[0].default_value = (0,1,0,1) # green RGBA
node_emission.inputs[1].default_value = 0.9 # strength
node_emission.location = 0,0
# create output node
node_output = nodes.new(type='ShaderNodeOutputMaterial')
node_output.location = 400,0
# link nodes
links = mat.node_tree.links
link = links.new(node_emission.outputs[0], node_output.inputs[0])
ob.data.materials.append(mat)
node = bpy.context.active_object.active_material.node_tree.nodes['Emission']
node.inputs[1].keyframe_insert(data_path="default_value",frame=1)
bpy.context.area.type = 'GRAPH_EDITOR'
bpy.ops.graph.sound_bake(filepath=r'C:\Users\andga\Desktop\Garrett\Music\Knife Party\Singles & EP\2012 - Rage Valley\01-knife_party-rage_valley.mp3', attack = 0.0001, release = 1.1)
# pick the fcurve to add to
fcurve = ob.animation_data.action.fcurves[0] #here is were the error comes from
# add a modifier and get a reference.
limits = fcurve.modifiers.new(type='LIMITS')
limits.use_max_x = True
limits.max_x = 0.0
limits.use_influence = True
limits.influence = 0.5