[Tutor] Specifying the selected object number in Blender

Steven D'Aprano steve at pearwood.info
Wed Aug 6 03:00:49 CEST 2014


On Tue, Aug 05, 2014 at 12:35:57PM -0500, Marcus Mravik wrote:
> I am trying to specify a number based on what the selected object number in
> the scene is.

Well, I have no idea about Blender, but if "selected object number" is 
just an int, starting from 0 (or perhaps 1) and incrementing by 1 each 
time, you can do that with a simple for-loop:

import bpy
filename = "C:\\Users\\Marcus\\Music\\Don't Just Stand There (Instrumental).mp3"

for selected_object_number in range(0, 160):
    low = 50*selected_object_number

    for obj in bpy.context.selected_objects:
        bpy.context.scene.objects.active = obj
        bpy.ops.graph.sound_bake(filepath=filename, low=low, high=low+50)


-- 
Steven


More information about the Tutor mailing list