Blender Script made to help separate camera or mesh data quickly from their rig. Made with the help of AI. Blender version 4.3.
Python
"""
This Python script, "JD Bake Duplicate", (v1.0.0),
is part of a project created by Jonathan DeLeon.
Copyright (C) 2025 Jonathan DeLeon (contact@JonathanDeLeon.com)
This script is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This script is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import bpy
from mathutils import Matrix
def get_unique_name(base_name):
version = 1
while True:
name = f"{base_name}{version:03}"
if name not in bpy.data.objects:
return name
version += 1
def copy_static_camera_properties(src, dst):
dst.type = src.type
dst.sensor_fit = src.sensor_fit
dst.sensor_width = src.sensor_width
dst.sensor_height = src.sensor_height
dst.clip_start = src.clip_start
dst.clip_end = src.clip_end
dst.dof.use_dof = src.dof.use_dof
if src.type == 'ORTHO':
dst.ortho_scale = src.ortho_scale
def bake_object_world_space(obj):
scene = bpy.context.scene
start = scene.frame_start
end = scene.frame_end
if obj.type == 'CAMERA':
base_name = "cam_baked_v"
bpy.ops.object.camera_add(location=(0, 0, 0), rotation=(0, 0, 0))
baked_obj = bpy.context.active_object
baked_obj.name = get_unique_name(base_name)
# Move to top-level collection
for collection in baked_obj.users_collection:
collection.objects.unlink(baked_obj)
bpy.context.scene.collection.objects.link(baked_obj)
baked_cam_data = baked_obj.data
original_cam_data = obj.data
# Copy all static camera settings
copy_static_camera_properties(original_cam_data, baked_cam_data)
elif obj.type == 'MESH':
base_name = "mesh_baked_v"
# Create a new object with the same mesh data (but no parenting or constraints)
mesh_data = obj.data
baked_obj = bpy.data.objects.new(get_unique_name(base_name), mesh_data)
bpy.context.scene.collection.objects.link(baked_obj)
else:
print("❌ Unsupported object type.")
return
# Bake transforms (and camera properties if applicable)
for frame in range(start, end + 1):
scene.frame_set(frame)
mat_world: Matrix = obj.matrix_world.copy()
loc = mat_world.to_translation()
rot = mat_world.to_euler()
baked_obj.location = loc
baked_obj.rotation_euler = rot
baked_obj.keyframe_insert(data_path="location", frame=frame)
baked_obj.keyframe_insert(data_path="rotation_euler", frame=frame)
if obj.type == 'CAMERA':
baked_cam_data.lens = original_cam_data.lens
baked_cam_data.dof.aperture_fstop = original_cam_data.dof.aperture_fstop
baked_cam_data.dof.focus_distance = original_cam_data.dof.focus_distance
baked_cam_data.keyframe_insert(data_path="lens", frame=frame)
baked_cam_data.dof.keyframe_insert(data_path="aperture_fstop", frame=frame)
baked_cam_data.dof.keyframe_insert(data_path="focus_distance", frame=frame)
if original_cam_data.type == 'ORTHO':
baked_cam_data.ortho_scale = original_cam_data.ortho_scale
baked_cam_data.keyframe_insert(data_path="ortho_scale", frame=frame)
print(f"✅ Baked object '{baked_obj.name}' created in top-level collection.")
def run_bake():
selected = bpy.context.selected_objects
if not selected or len(selected) != 1:
print("❌ Please select one camera or mesh object.")
return
obj = selected[0]
if obj.type not in {'CAMERA', 'MESH'}:
print("❌ Selected object must be a camera or mesh.")
return
bake_object_world_space(obj)
# Run the tool
run_bake()
Python