Blendercookie-Building an Audio Visualizer in Python need help

I am having trouble, when I run the script is says error- python script fail look in console for now and it highlights
spiral(rows, columns)
then in the console it says
AttributeError: Calling operator “bpy.ops.object.scale_apply” error, could not be found
the script is

  • import bpy
  • rows = 3
  • columns = 3
  • r = 0
  • c = 0
  • def spiral(X, Y):
  • x = y = 0
    
  • dx = 0
    
  • dy = -1
    
  • for i in range(max(X, Y)**2):
    
  •     if (-X/2 < x <= X/2) and (-Y/2 < y <= Y/2):
    
  •         bpy.ops.mesh.primitive_cube_add(location = (x, y, 0))
    
  •         bpy.context.scene.cursor_location = bpy.context.active_object.location
    
  •         bpy.context.scene.cursor_location.z -= 1
    
  •         bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
    
  •         bpy.context.active_object.scale.x = 0.5
    
  •         bpy.context.active_object.scale.y = 0.5
    
  •         bpy.context.active_object.scale.z = 5
    
  •         bpy.ops.object.scale_apply()
    
  •         bpy.ops.anim.keyframe_insert_menu(type='Scaling')
    
  •         bpy.context.active_object.animation_data.action.fcurves[0].lock = True
    
  •         bpy.context.active_object.animation_data.action.fcurves[1].lock = True
    
  •         bpy.context.area.type = "GRAPH_EDITOR"
    
  •         step = 20000/ (rows*columns)
    
  •         bpy.ops.graph.sound_bake(filepath="/Users/jaycarter/Desktop/Square Tiles.m4a", low=i*step, high=i*step + step)
    
  •         bpy.context.active_object.animation_data.action.fcurves[2].lock = True
    
  •         if x == y or (x < 0 and x == -y) or ( x > 0 and x == 1-y):
    
  •             dx, dy = -dy, dx
    
  •         x, y = x+dx, y+dy
    
  •       spiral(rows, columns)
    

I have attached the blend

I am using a build off graphicall it is a luxblend 2.57.1 r36543, I tried it in a older version to that i still have but still wont work and on the official version

What am I doing wrong?

Attachments

pulse.blend (583 KB)

It looks like you are using an older version of the Blender Python API. If you look at current docs for what you can do on an Object:

http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.Object.html

you will see that there is no ‘scale_apply’ operator (used on line 19 of your script). I’m not even sure you need it - I think just assigning to the scale attributes might be enough.

still didn’t work, any other advice

swap :
bpy.ops.object.scale_apply()

for:
bpy.ops.object.transform_apply(scale=True)

this should sort it out, its on the tutorial 2nd page at top lots of users getting caught out on this :slight_smile:

still getting the same error. I hope this screenshot helps


any one has a complete working script in latest built for this small animation

i’ll check out the video but not certain if i can make it work may be du to some API changes!

happy 2.5

Hi newdles, I’m using build 2.57.1 r37390 and the script runs fine in this build but you must swap
bpy.ops.object.scale_apply()
to:
bpy.ops.object.transform_apply(scale=True)
Hope this helps

I’ve only watched the tutorial, but after amending with the spiral function, I would have thought this line:


step = 20000 / (rows*columns)

would want to become:


step = 20000 / (X*Y)

help when id try running the script it crashes blender? any ideas? ive tried using newer versions but still didnt work?

Thank you for this tip. Now my script runs. :smiley: