@X Y, here is the code that's not working. Thank you again!
And one last question, if I wanted to modify one of the Noise modifier's parameters like scale, how would I go about doing that? Since it's an fcurve in the graph editor, I'm not sure how to go about doing that.
def get_fcurves_set(ob):
if hasattr(ob, "animation_data"):
animation_data = ob.animation_data
if hasattr(animation_data, "action"):
action = animation_data.action
if hasattr(action, "fcurves"):
return set(action.fcurves)
return set()
def anim_bend(input_name, bend_angle):
obj = bpy.context.active_object
# for each selected object, run this
for obj in bpy.data.objects:
if input_name in obj.name:
#select objects individually
ob = bpy.context.scene.objects[obj.name] # Get the object
bpy.ops.object.select_all(action='DESELECT') # Deselect all objects
bpy.context.view_layer.objects.active = ob # Make the cube the active object
ob.select_set(True) # Select the object
print(obj.name, ": Selected Successfully")
modBendName = "SimpleDeform_Bend"
for modifier in obj.modifiers:
if modifier.name == modBendName:
obj.modifiers.remove(obj.modifiers.get(modBendName))
print(obj.name, ": DELETED existing", modBendName)
modBend = obj.modifiers.new(name= modBendName, type='SIMPLE_DEFORM') # add simple Deform to mesh
modBend.deform_method = 'BEND' # change deform to bend
modBend.angle = math.radians(bend_angle) # set initial angle before adding animated noise
#modBend.keyframe_insert("angle",frame=0) # add key on frame 0
ob = bpy.context.object
old_fcurves = get_fcurves_set(ob)
success = bpy.context.object.keyframe_insert("location", index=0)
if success:
new_fcurves_added = get_fcurves_set(ob) - old_fcurves
fc = list(new_fcurves_added)[0]
fmd = fc.modifiers.new("NOISE")
#fNoise = bpy.ops.graph.fmodifier_add(type='NOISE')
print(obj.name, ": Added", modBendName)
```