Is there any way to replace some object with another object?
For example, I have a bunch of cubes randomly placed throughout my project I want to replace those cubes with spheres. How can I replace the objects?
As usual there is may ways to achieve this. One approach would be to use the Link Object Data
function, which basically allows you to swap out the Mesh Data (i.e. what you have in Edit Mode
) with a selected mesh. The shortcut is Ctrl + L. See it in action here:
Whichever method you choose, you might get issues in regards to scale. If your cubes have different scale values in the Transform Panel, the spheres will have those different scales as well. If you had applied the scale before, all final spheres will be equally sized.
Even more important is the scale of the sphere. If that is not applied, but the cubes are, the resulting spheres will have a different size than the 'original'. The reason for both behaviors is this: The final representation of an object is a combination of Object
and Object Data
. The object holds the location, rotation and scale values. The data holds the mesh vertex coordinates, face info, etc. But the mesh data stores this info always as if the scale was 1. The output for the user is however displayed as the combination of both at all times. So before the sphere gets displayed on the screen, Blender applies the transformation matrix onto each vertex, and shows you the final result.
Final note: With this method, all objects will share the same mesh data. If you manipulate one, all of them will update when you exit Edit Mode
.
Following is the way to use Python scripting to solve the problem.
import bpy
active_object = bpy.context.active_object
# Ignore the last element of the list (which is the active object)
selected_objects = bpy.context.selected_objects[:-1]
if not selected_objects:
raise ValueError("Only one object selected")
meshes_to_remove = set()
for item in selected_objects:
meshes_to_remove.add(item.data)
item.data = active_object.data
for mesh in meshes_to_remove:
# If the mesh is still being used by other objects,
# or if the user explicitly wants to keep the mesh around,
# let us not remove it
if mesh.users or mesh.use_fake_user:
continue
# If we are here, we are safe to remove the mesh
print("removing ", mesh)
bpy.data.meshes.remove(mesh)
Yes there is! I developed a blender extension back in 2013 but it still works. I stopped developing it however because I don't have time, so it is possible that there are some little bugs.
Look here: https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Material_Search
I just tested it with Blender v2.79 and it still works