automation

Automation in Blender: 8 ways to simplify repetitive tasks.

Often we want to perform an action to many objects in Blender. The most common way is to select all objects of interest, then ask Blender to manipulate them in some way.

In many cases Blender just does what we expect and that’s great. Other times there are simple (tho sometimes obscure) workflows built inside Blender. And finally, there are situations where we either have to manipulate each individual object by hand or … use Python scripting ( 😱 ).

Let’s go through each common situation one by one. We’ll start with the simplest. Around the end I’ll share a simple script I use all the time when Blender’s default tools fail me.

⚠️ Active Object vs Selected Objects

Before we go further tho, there is one thing that we must understand and that’s Blender’s idea of “Active Object” and “Selected Objects”. Experienced users can skip this section.

When we click on object we say that we “select” it. And that’s correct but also, we’re making it the Active Object. Only the properties of the Active Object are displayed in the Properties window. And certain operations are only performed on the Active Object, and NOT on all selected… at least not by default.

When we shift+click another object we add it to the group of selected objects and also make it the new Active Object. In the default Blender theme all selected objects are highlighted in dark orange, while the Active Object is bright orange.

There can be unlimited number of Selected Objects but the Active Object is always only one.

Blender, Active Object, Selected Objects

I’ll explain some uses of Active and Selected Objects in a minute. Let’s move on to the examples.

💠 When blender simply does its job

Quite a lot of operations are applied to the whole selection by default. Most commands under the Object menu will do just that.
(There are some exceptions as shown in the image).

Blender object actions menu

Moving, rotation, scaling, setting origin, applying transforms, setting key-frames etc. etc. These operations are applied on the whole selection as you’d expect.

💠 Copying properties from Active to Selected

Blender allows you set up some attributes for just one object, then copy them to many others.

An example of this is the CTRL+L menu (I’ve indicated the options I use often). It allows you to transfer data from the Active Object to all Selected ones. This is where Active vs Selected Objects becomes important.

Blender CTRL+L menu

Another example of this is the Copy Attributes Menu addon. It comes with Blender but is not activated by default, make sure you activate it.

Blender Copy Attributes Menu addon

When you do, pressing Ctrl+C in the 3d view will bring up a special menu with several options, all of which try to copy data from one object (the Active Object) to other objects (all Selected Objects)

💠 Telling blender to affect all selected (a.k.a. the ALT-key “trick”)

This is a slightly obscure Blender feature that many users don’t know about. It allows you to simultaneously change parameters on multiple objects.

This “trick” mostly applies to the attributes in the following tabs of the Properties Window. To be precise it mostly applies to the Object Properties and Object Data Properties which I have indicated with arrows.

Blender Properties Window

Again it’s important to keep in mind Active vs Selected Objects.

Let’s say you have multiple selected objects one of which is the Active one. Tweaking properties in the Properties window will normally only affect the Active object. However, if you hold ALT-key while tweaking a parameter it will (in many cases) affect the whole selection.
Let’s demonstrate that with examples.

In the following GIF I show 3 different ways to use the “ALT-key trick”. As you can see there are several ways to apply it. Each produces a slightly different result:
· hold ALT while dragging a Value parameter
· hold ALT while you click on the Value parameter, then enter a value, then press Enter
· click on the Value parameter, enter a value, then press ALT+Enter

Blender. Manipulate many objects with ALT key. GIF
click to enlarge

The above example is not extremely practical but it’s good for showing all variations of the technique. Here I something I actually use often: Setting up Auto Smooth for several objects.

Blender. Auto Smooth on many objects with ALT key. GIF
click to enlarge

This should give you an idea how to use the ALT key to tweak many objects at once. In general it can be applied to all Checkboxes and Value parameters that are shared between Objects. I encourage you to add a few spheres and monkeys to a scene and ALT+click around to see what happens.

However, there are many buttons and options in the Properties window where ALT+click does nothing!

Examples that don’t work with ALT

🔴 Adding/Removing Materials etc.

Anywhere you see the +/- signs for adding and removing Materials/Vertex Paint/Vertex Weight/UVs etc. will not work with ALT. However if there is a a little downward arrow below them, it may contain options that allow you to apply an action to many objects.

Add Remove Materials Vertex Paint, Vertex Weight, UVs

🔴 Clear Custom Split Normals

If you have worked with imported meshes in Blender you may know this little troublemaker. I honestly don’t know what it’s for, my only experience with it is trying to get rid of it (on many objects in some cases). ALT-clicking it will not affect all objects, just the Active one. 🙁

Clear Custom Split Normals

🔴 Modifiers and Constraints

You can’t add Modifiers or Constraints to many objects at the same time. However, you can copy them from the active to selected objects as explained above (using CTRL+L).

💠 Manual Work (aka “Don’t be lazy”)

Let’s face it. There will be times when you need to do an action to 653 objects.
Yet Blender doesn’t give you a good tool for the job.
There is no addon for it either.
You know there is a scriptable solution but you can’t figure it out.
If it’s a one-off task you can just do it by hand. Yeah, it’s going to be a boring 30 minutes, maybe an hour. But once it’s done you can move on with your work. That’s better than spending 5 hours googling a solution.

💠 Repeat Last Action (Shift+R)

Repeat Last Action, shortcut Shift+R can be very useful. It works with almost any command or operation you can think of.

Try it. Create a couple of objects. Select one and perform an action. E.g. add a Subdiv modifier, add or delete a Vertex Group, rotate or scale the object etc. etc.
Then select another object and press Shift+R. The same last action will be performed on the second object.

💠 Using Addons

There are a bunch of addons that can help with repetitive tasks. Here is a few I can think of. If you know other ones, write in the comments section. Pretty please! I really want to give them a try.

  • Batch Operations – a monster addon that I don’t actually use but it seems powerful.
  • Copy Attributes Menu addon: already mentioned above.
  • Commotion: has many functions but the one I’ve used a lot is Offset Animation, which can be applied to hundreds of objects. Useful in creating beautiful motion graphics.
  • Command Recorder Addon – you can think of it as “Repeat Last Action (Shift+R)” on steroids. Allows you to record a set of actions (or “macros” as they are called in other software) and then perform them again and again with a click of a button.

💠 Custom Scripts

This is why I started writing this article in the first place. I found out that with a few lines of Python script I can easily repeat almost any action or a set of actions to a group of objects.

This is what it looks like:

import bpy

sel = bpy.context.selected_objects

for obj in sel:
	bpy.context.view_layer.objects.active = obj
	#action to be performed on each selected

What the script does is create a list of all selected objects. Then it goes through the list. For each object, first it makes it the Active Object. Then it performs one or more actions on it. Then it moves to the next one and so on until the list is over.
Obviously you have to replace the last line with something useful.

Concrete Examples

🟢 Remove Custom Split Normals on all selected

The annoying Custom Split Normals I mentioned earlier. With 5 lines of code I can remove them from hundreds of objects if I need to.

import bpy

sel = bpy.context.selected_objects

for obj in sel:
	bpy.context.view_layer.objects.active = obj
	bpy.ops.mesh.customdata_custom_splitnormals_clear()

🟢 Give all Selected random Rotation and Scale

Slightly more complex example to show that you’re not limited to performing a single action.

I actually used this in practice recently. I wanted to drop a few hundred rigid bodies but I wanted each one to have a random initial rotation and scale.

(In this case setting the active object ( bpy.context.view_layer.objects.active = obj) is actually not necessary but it doesn’t hurt either so I left in there)

import bpy
import random #Python library for dealing with random numbers

sel = bpy.context.selected_objects

for obj in sel:
	bpy.context.view_layer.objects.active = obj
	random_scale = random.randint(50,100)/100
	obj.scale = (random_scale,random_scale,random_scale)
	random_rot_x = random.random()*360
	random_rot_y = random.random()*360
	random_rot_z = random.random()*360
	obj.rotation_euler = (random_rot_x, random_rot_y, random_rot_z)

So I use this all the time now. I copy and paste this Python snippet. The rest depends on finding out the right Python command I want to use.

There are a few simple steps I take when I look for a suitable Python code.
Here is a screenshot of my “Hacking” workspace and the general workflow.
1. Find out the command you need. Very often you’ll find it in a tooltip
2. Another way to find a Python command is is from the Info Window
3. Test the command in the Python Console
4. Write the actual script
5. Did you get the desired result. Yes? Great. No? Redo the above steps with different inputs.

If you don’t see tooltips, make sure your Interface is setup correctly:

Blender Preferences Tooltips

And of course if you’re stuck, there is the Python API Reference and Google.

Conclusion

I tried to convey the main methods for manipulating large amounts of objects in Blender. Obviously, I haven’t covered everything but I hope you learned something interesting. Know something interesting that I haven’t mentioned here? Let us know!