Is there a way to do a particular task manually, generate the code for it automatically and update that code to do some task repeatedly?
I'm looking for something like record macro functionality that's available in MS Excel.
If you pull down the Info header you will find that a fair amount of operations you can perform in Blender are printed there for relatively simple stuff such as adding a lamp or a modifier etc.
import bpyat the top of the text block.
After that, if you were to have a look at the api, you could cut out much of the fluff and just use said commands in a script to reuse whenever you need to provided it is simple enough and in the correct context.
bpy.ops.mesh.primitive_cube_add( radius=1.0, view_align=False, enter_editmode=False, location=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0), layers=(False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
... can be shortened to
bpy.ops.mesh.primitive_cube_add() in most situations.
This is as close to a macro like functionality that you can get in Blender and it is linear so any actual repetitive bits will have to be crafted by you, loops etc. It is also worth noting that many of these commands need to be run in a specific context so I would recommend using it as a means of learning the correct calls instead of trying to reuse it directly.
For most operations, there is an accompanying line of code printed. Including changing numeric values, toggles... etc.
Excluded operations are typically not useful to redo, zooming/panning, setting the cursor location... etc.
As mentioned above, repetitive tasks in blender are scripted in python.
When blender is launched with
--debug-wm argument , python expression corresponding to executed user actions are printed in console of Info panel and also can be a reference for simple macro script creation.
Also, not exactly same as Excel macros but macro recorder add-on is useful to record a a set of user's actions as python script, while editing a mesh for example and refactor it for reuse if necessary.