7
$\begingroup$

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?

$\endgroup$
14
$\begingroup$

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:

link_data

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.

$\endgroup$
  • $\begingroup$ Perfect and thanks. One more additional to it if the cube have a random shape (i.e. big small medium) will this work $\endgroup$ – atek Oct 16 '16 at 6:46
  • $\begingroup$ @atek that's what I mean with the scale. If in the transform panel the scales of the various cubes are different, the scales of the spheres will be different. Otherwise not. $\endgroup$ – aliasguru Oct 16 '16 at 7:23
0
$\begingroup$

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

$\endgroup$
  • 2
    $\begingroup$ Can you explain what benefits this has over the linking method. If I had multiple objects I could just select the material for the active one and press Ctrl L > link materials which is the same amount of steps as in your addon. $\endgroup$ – Leander May 31 '18 at 9:39
  • $\begingroup$ @Leander, The advantage is obviously that you can do this via the toolbar and don't have to remember the hotkeys needed to do this. And it is more beginner friendly. You can also replace materials and it has a function to list all objects from the scene and jump to them on click. It combines multiple features in one single place. $\endgroup$ – Black May 31 '18 at 15:32
  • $\begingroup$ I'm guessing it's simply not my thing. In case you didn't know about, you might be interested in bforartists which was mentioned in another question earlier. $\endgroup$ – Leander May 31 '18 at 15:44
0
$\begingroup$

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)
$\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.