# use the info view to retrieve commands
# create a new (pre-defined) object
# resize the selected object
# give a name to the selected object
# create a new material
# assign a material to an object
# set a keyframe for selected objects (location)
# translate the object with new keyframe
# select / unselect objects / select all objects
# review the system console for messages and errors
Here is the python file with all commands used:
ReplyDeleteimport bpy
# create a new (pre-defined) object
bpy.ops.mesh.primitive_cube_add(location=(0,0,0))
# resize the selected object
bpy.ops.transform.resize(value=(0.5,0.5,0.5))
# give a name to the selected object
bpy.context.object.name = "newobj"
# create a new material
bpy.data.materials.new("newmat")
bpy.data.materials["newmat"].type = 'SURFACE'
bpy.data.materials["newmat"].diffuse_color = (1, 0, 0)
# assign a material to an object
bpy.data.objects['newobj'].active_material = bpy.data.materials['newmat']
# set a keyframe for selected objects (location)
bpy.context.scene.frame_set(frame=1)
bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success=False, always_prompt=False)
# translate the object with new keyframe
bpy.context.scene.frame_set(frame=50)
bpy.ops.transform.translate(value=(1,0,0))
bpy.ops.anim.keyframe_insert_menu(type='Location', confirm_success=False, always_prompt=False)
##### usefull also
# select all objects
for object in bpy.data.objects:
object.select = True
# select / unselect
bpy.data.objects["newobj"].select = True
bpy.data.objects["Camera"].select = False
bpy.data.objects["Lamp"].select = False