BASIC: bpy.data.meshes error

I am very noob to Blender Python scripting, trying to follow tutorial here:

http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Advanced_Tutorials/Python_Scripting/Export_scripts

The weird thing is, something so straight forward trying to run this from the Python Console window:

cubedata = bpy.data.meshes[‘Cube’]

Give me error:

Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
KeyError: ‘bpy_prop_collection[key]: key “Cube” not found’

Any idea why?

I am using the Blender built 2.61.0 r42615

you’ve got no object named ‘Cube’ in scene or in memory… that’s why
try it on default scene and should work, or add an object named Cube

I think it’s a bug because I am sure there is Cube, Lamp, Camera in the scene.

I tried using older version of Blender and it works.

Next weird thing:

import Blender

This does not seem to work anymore, I think there is no Blender module anymore.

import Blender is from 2.49, it no longer exists in the new API.

The name of your cube mesh is not named “Cube”. Although it typically is in a default scene.

Try:


import bpy

ob = bpy.data.objects["Cube"]
cube_data = ob.data
print(cube_data.name)
# Redundantly fetch the same data.
cubedata = bpy.data.meshes[cube_data.name]

@Atom

I see, you are right, since my scene is not really the default scene, apparently the Cube Object I have at this scene is actually stored as vertex data named “Cube.004” (I looked under Outliner).

I re-load Factory Settings and now it is good.

“Import Blender” is no longer available, isn’t it? Ok, apparently I am following the old tutorial hmm… I will find different source.

Thanks all~