I just started yesterday with python scripts in blender but im using blender for 2 years now.
After I finished my Sound Visualizer yesterday, i thought it does look kinda boring with just moving bars.
Therefore I decided to try to create a code for a sound visualizer, at which each bar which would previously scale along the z axis would be replaced by a plane which does emit particles. My goal is it to make the particles lifetime change according to the way in which the bars got sclaed along the z axis previously.
neither ParticleSettings.count = 100000 (and the following lines) nor bpy.data.particles(“ParticleSetting.001”).count = 100000 does work.
I got no Idea how to create a keyframe for the lifetime of particles via python. In my first Visualizer I could just use bpy.ops.anim.keyframe_insert_menu(type=‘Scaling’), but i guess thats not working now ;). Therefore i tought bpy.ops.anim.keyframe_insert_button() might work, but i dont find/know any syntax on how to use it …
I hope my very bad english didnt kept you from understanding what im talking about every help would be really apreciated
woow, thanks! Thats by far more then I could expect
i kept working on it and thats its current state:
import bpy
bars = 3
startframe = 1
endframe = 4250
c = 1
steps = 8000/bars
for i in range(0, bars):
bpy.ops.mesh.primitive_plane_add(location = (c, 1, 0)) # c == i+1
ob = bpy.context.active_object
ob.scale.x = 0.5
ob.scale.y = 0.5
bpy.ops.object.particle_system_add()
pss = ob.particle_systems.active.settings
pss.count = 100000
pss.frame_start = startframe
pss.frame_end = endframe
pss.normal_factor = 100
pss.factor_random = 5
pss.material = 1
pss.lifetime=0
pss.keyframe_insert("lifetime", frame=1)
#pss.lifetime = 10
#pss.keyframe_insert("lifetime", frame=100)
bpy.context.area.type = 'GRAPH_EDITOR'
bpy.ops.graph.sound_bake(filepath="/Users/Till/Desktop/ShakeDrizzle 4 President/ShakeDrizzle's Music Playlist/The Two Friends ft. Jeff Sontag - Sedated (Culture Code Remix).mp3", low=steps*i, high=steps*i+steps, attack=0.01, release=0.2)
#Changes the first key interpolation from bezier to linear.
#pss_fcurves = pss.animation_data.action.fcurves
#for curve in pss_fcurves:
# if curve.data_path == "lifetime":
# break;
#curve.keyframe_points[0].interpolation = "LINEAR"
c += 1
bpy.context.area.type = 'TEXT_EDITOR'
My current problem is that there is a correct graph which gets assigned to the lifetime of each single particle system but the lifetime isnt changing at all if I run the animation Probably you can try it yourself and just change the path of the .mp3 used.
Would cool if you/anyone got an idea how to fix this/ can tell me what I did wrong.
If you got some more spare time it would be cool if you could answer two small other questions of mine:
I’ve looked for lines of code at google and blender.org which would do what i needed (in my first post) but only found ones which didnt worked. How can I find the correct lines of code for my purpose more precisly? Always using the forum to ask people cant be the real way
What exactly are you trying to achieve with “Changes the first key interpolation from bezier to linear.”? I just commented it since I had no idea what it did and it made seemingly to me no difference if its in the code or not
woow, thanks! Thats by far more then I could expect
i kept working on it and thats its current state:
import bpy
bars = 3
startframe = 1
endframe = 4250
c = 1
steps = 8000/bars
for i in range(0, bars):
bpy.ops.mesh.primitive_plane_add(location = (c, 1, 0)) # c == i+1
ob = bpy.context.active_object
ob.scale.x = 0.5
ob.scale.y = 0.5
bpy.ops.object.particle_system_add()
pss = ob.particle_systems.active.settings
pss.count = 100000
pss.frame_start = startframe
pss.frame_end = endframe
pss.normal_factor = 100
pss.factor_random = 5
pss.material = 1
pss.lifetime=0
pss.keyframe_insert("lifetime", frame=1)
#pss.lifetime = 10
#pss.keyframe_insert("lifetime", frame=100)
bpy.context.area.type = 'GRAPH_EDITOR'
bpy.ops.graph.sound_bake(filepath="/Users/Till/Desktop/ShakeDrizzle 4 President/ShakeDrizzle's Music Playlist/The Two Friends ft. Jeff Sontag - Sedated (Culture Code Remix).mp3", low=steps*i, high=steps*i+steps, attack=0.01, release=0.2)
#Changes the first key interpolation from bezier to linear.
#pss_fcurves = pss.animation_data.action.fcurves
#for curve in pss_fcurves:
# if curve.data_path == "lifetime":
# break;
#curve.keyframe_points[0].interpolation = "LINEAR"
c += 1
bpy.context.area.type = 'TEXT_EDITOR'
My current problem is that there is a correct graph which gets assigned to the lifetime of each single particle system but the lifetime isnt changing at all if I run the animation Probably you can try it yourself and just change the path of the .mp3 used.
Would cool if you/anyone got an idea how to fix this/ can tell me what I did wrong.
If you got some more spare time it would be cool if you could answer two small otehr questions of mine:
I’ve looked for lines of code at google and blender.org which would do what i needed (in my first post) but only found ones which didnt worked. How can I find the correct lines of code for my purpose more precisly? Always using the forum to ask people cant be the real way
What exactly are you trying to achieve with “Changes the first key interpolation from bezier to linear.”? I just commented it since I had no idea what it did and it made seemingly to me no difference if its in the code or not