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.

up vote 12 down vote accepted

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.

This example:

  • adds a cube
  • scales it by 2.0
  • translates on the Z axis by 1.0.
  • sets the color to red
  • shows the name
  • renames the object.

enter image description here

  • Select the lines (mouse-click, border-select or AKey)
  • Ctrl+C to copy the selected lines.
  • Paste into the text editor.
  • add import bpy at 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.

For example:

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.

Note

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.

  • 1
    Note that not all operations are logged, and changes in the context (which operators rely on) don't necessarily appear in the operator log. – CoDEmanX Jan 20 '14 at 20:03
  • @CoDEmanX I did say most, will add a bit more info shortly. – iKlsR Jan 20 '14 at 23:02
  • 1
    I refered to "reuse whenever you need to", which sounded like you could run the copied ops whenever you want to. But it's not true, 'cause of the context requirements. Thus, it's not a proper macro system, 'cause it will mostly require touch-up to make it work (under several conditions). It can be misleading to see the operator log and think of it as a macro system. I would appreciate a full action serialization in Blender of course (to allow for true macro recording), but it's not going to happen any time soon. – CoDEmanX Jan 20 '14 at 23:50
  • @iKlsR how to save and add in macro list and give hotkeys not mention. I have seen an video youtube.com/watch?v=zMxkU350SaE in that video the shortcut are made in the menu time its coming from beside the mouse pointer. – atek Nov 13 '16 at 14:38

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.

There is also paid nice UI based macro editing feature in Pie Menu Editor add-on

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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