1
$\begingroup$

I was trying to save history of changes to Python script by using Info Editor type. Here is my example script:

bpy.ops.mesh.primitive_plane_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.transform.resize(value=(-7.70136, -7.70136, -7.70136), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
bpy.context.space_data.context = 'PHYSICS'
bpy.ops.rigidbody.object_add()
bpy.context.object.rigid_body.type = 'PASSIVE'
bpy.ops.rigidbody.object_add()
bpy.context.space_data.context = 'OBJECT'
bpy.context.space_data.context = 'PHYSICS'
bpy.context.object.rigid_body.collision_shape = 'BOX'
bpy.context.space_data.context = 'OBJECT'
bpy.context.space_data.context = 'WORLD'
bpy.context.space_data.context = 'OBJECT'
bpy.context.object.scale[0] = 2
bpy.context.object.scale[1] = 1
bpy.context.object.scale[2] = 0.5
bpy.context.object.scale[1] = 0.7
bpy.context.object.location[2] = 0.5
bpy.context.object.scale[2] = 0.3
bpy.context.object.location[2] = 0.3
bpy.context.object.scale[0] = 3
bpy.context.object.location[1] = 1.5
bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False})
bpy.context.object.location[1] = -1.5
bpy.context.area.type = 'INFO'

History of changes: I made, manually (in 3d editor) two physical blocks lying on plane.

Space 1

Now I want to get same effect by pasting saved script into python console - but I got this:

enter image description here

Apparently the interpreter took and resized planes to shape of blocks, but it couldn't hold idea of 'BOX' object. What do I do wrong?

$\endgroup$
3
$\begingroup$

While the info window is helpful it does not show a complete list of actions taken, the steps it does show can be expanded.

While copy and pasting an operator is an easy way to duplicate some steps in a python script, it is usually preferred to directly alter the data in a python script rather than just calling operators. You can find the reference to blender's python api online which also has some introduction tutorials to get you started.

For an example of creating a mesh object you could have a look at the add object addon template that is included with blender.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.