def create(name: str, location: Vector, template: Object, collection: Collection) \ -> bpy.types.Object: obj = template.copy() obj.name = name obj.location = location collection.objects.link(obj) return obj
def duplicate(obj:Object, linked:bool=False, link_to_scene:bool=False): """ efficient duplication of objects """ copy = obj.copy() if not linked and copy.data: copy.data = copy.data.copy() copy.hide = False if link_to_scene: bpy.context.scene.objects.link(copy) return copy
def duplicate(obj: Object, linked: bool = False, link_to_scene: bool = False): """ efficient duplication of objects """ copy = obj.copy() if not linked and copy.data: copy.data = copy.data.copy() unhide(copy, render=False) if link_to_scene: link_object(copy) return copy
def duplicate(obj:Object, linked:bool=False, link_to_scene:bool=False): """ efficient duplication of objects """ copy = obj.copy() if not linked and copy.data: copy.data = copy.data.copy() unhide(copy, render=False) if link_to_scene: link_object(copy) return copy
def _create_dstr(ob: Object, curve: Object, sizes: list, con_add=True) -> list[tuple[Constraint, float, float]]: space_data = bpy.context.space_data use_local_view = bool(space_data.local_view) ob_colls = ob.users_collection child_colls = [(child, child.users_collection) for child in ob.children] obs = [] app = obs.append for is_last, size in iterutils.spot_last(_flatten(sizes)): if is_last: ob_copy = ob else: ob_copy = ob.copy() for coll in ob_colls: coll.objects.link(ob_copy) if use_local_view: ob_copy.local_view_set(space_data, True) for child, colls in child_colls: child_copy = child.copy() for coll in colls: coll.objects.link(child_copy) child_copy.parent = ob_copy child_copy.matrix_parent_inverse = child.matrix_parent_inverse if con_add: con = ob_copy.constraints.new("FOLLOW_PATH") con.target = curve con.use_curve_follow = True con.forward_axis = "FORWARD_X" else: for con in ob_copy.constraints: if con.type == "FOLLOW_PATH": break scaling = size / ob_copy.dimensions.y if not _eq(scaling, 1.0): ob_copy.scale *= scaling app((con, None, size)) return obs
def ob_copy_to_faces(ob: Object) -> None: mats = mesh.face_pos() if mats: ob.matrix_world = mats.pop() collection = bpy.context.collection space_data = bpy.context.space_data use_local_view = bool(space_data.local_view) for mat in mats: ob_copy = ob.copy() collection.objects.link(ob_copy) ob_copy.matrix_world = mat ob_copy.select_set(True) if use_local_view: ob_copy.local_view_set(space_data, True)
def ob_copy_and_parent(ob: Object, parents: Iterable[Object]) -> None: is_orig = True space_data = bpy.context.space_data use_local_view = bool(space_data.local_view) for parent in parents: if is_orig: ob_copy = ob is_orig = False else: ob_copy = ob.copy() for coll in parent.users_collection: coll.objects.link(ob_copy) if use_local_view: ob_copy.local_view_set(space_data, True) ob_copy.select_set(True) ob.location = parent.location ob.rotation_euler = parent.rotation_euler ob.parent = parent ob.matrix_parent_inverse = parent.matrix_basis.inverted()