1

I am trying to duplicate multiple objects resulting in the same location/rotation relative to each other. I can get my code to work for a single object but when multiple objects are used obviously the objects get transformed N times (N number of multiple objects). Is there a function that I am missing or a different approach?

import bpy
import bmesh

bm = bmesh.new() for i, o in enumerate(bpy.context.selected_objects): bm.from_mesh(o.data) bm.transform(o.matrix_world)

me = bpy.data.meshes.new("Mesh") bm.to_mesh(me) obj = bpy.data.objects.new("Object", me) # https://docs.blender.org/api/current/bmesh.ops.html bpy.context.collection.objects.link(obj)

Objects to be copied Output Transformed with o.matrix_world

batFINGER
  • 84,216
  • 10
  • 108
  • 233

1 Answers1

3

bm.transform transforms every vert.

Question code will be getting an accumulative effect of transforming every current vert in the bmesh by each objects world matrix.

Instead, only transform the newly "from_mesh'd" vertices

import bpy
import bmesh

bm = bmesh.new()

for i, o in enumerate(bpy.context.selected_objects): bm.from_mesh(o.data) bmesh.ops.transform( bm, verts = bm.verts[-len(o.data.vertices):], matrix=o.matrix_world, )

me = bpy.data.meshes.new("Mesh") bm.to_mesh(me) obj = bpy.data.objects.new("Object", me) # https://docs.blender.org/api/current/bmesh.ops.html bpy.context.collection.objects.link(obj)

Related

https://blender.stackexchange.com/a/149269/15543

batFINGER
  • 84,216
  • 10
  • 108
  • 233