https://www.youtube.com/watch?v=_9GYrjhjtdo
- User
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
This YouTube video is a comprehensive Blender animation tutorial by Justin at The CG Essentials that demonstrates how to create an exploded view animation - a technique where the parts of a 3D model separate and then reassemble to show how components fit together[1][6].
The tutorial uses a wooden clock model from SketchUp 3D Warehouse, chosen specifically because it imports with separate components, making it ideal for this animation technique[1][6]. The model is called "Wooden clock with Digital Indication" by Oleg Chipetko[1].
Importing the Model: The presenter uses the SketchUp importer extension to bring the model into Blender with separate geometry intact[1].
Setting Up the Animation:
Keyframing Process:
Camera Animation:
Rendering:
The tutorial highlights an important technical consideration: if you try to keyframe the middle position before the end position, the pieces may come back together with incorrect rotations[1]. This is likely related to the applying of rotation and scale settings[1].
This technique is useful for product visualization, technical illustrations, and demonstrating how mechanical objects work by visually breaking down their components[1][3].
create a python script to run in blender to automate this process
Here's a complete Python script that automates the creation of an exploded view animation in Blender, similar to the technique shown in the video. This script will separate model parts and create a smooth animation where components fly apart and then come back together.
import bpy
import math
import mathutils
from mathutils import Vector
def create_exploded_view_animation(
start_frame=1,
explosion_frame=50,
end_frame=100,
explosion_factor=2.0,
use_constraints=False
):
"""
Create an exploded view animation for a model.
Parameters:
- start_frame: Frame where animation starts (assembled state)
- explosion_frame: Frame where model is fully exploded
- end_frame: Frame where animation ends (assembled state again)
- explosion_factor: How far the parts should explode outward
- use_constraints: If True, use empty objects and constraints instead of direct keyframing
"""
# Store the selected objects (model parts)
scene = bpy.context.scene
scene.frame_start = start_frame
scene.frame_end = end_frame
selected_objects = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
if not selected_objects:
print("No mesh objects selected. Please select model parts.")
return
# Calculate the center point of all selected objects
center = Vector((0, 0, 0))
for obj in selected_objects:
center += obj.location
center /= len(selected_objects)
# Method 1: Using direct keyframing
if not use_constraints:
# Set initial keyframes (start position)
scene.frame_set(start_frame)
for obj in selected_objects:
obj.keyframe_insert(data_path="location", frame=start_frame)
# Set final keyframes first (end position same as start)
scene.frame_set(end_frame)
for obj in selected_objects:
obj.keyframe_insert(data_path="location", frame=end_frame)
# Set the explosion keyframes
scene.frame_set(explosion_frame)
# Change pivot to 3D cursor for explosion
bpy.context.scene.tool_settings.transform_pivot_point = 'CURSOR'
bpy.context.scene.cursor.location = center
# Move each part away from the center
for obj in selected_objects:
# Calculate direction vector from center to the object
direction = obj.location - center
# Normalize direction and apply explosion factor
if direction.length > 0:
direction.normalize()
# Move the object outward
obj.location = obj.location + (direction * explosion_factor * obj.dimensions.length)
# Insert keyframe for exploded position
obj.keyframe_insert(data_path="location", frame=explosion_frame)
# Set animation curve interpolation to ease in/out
for obj in selected_objects:
fcurves = obj.animation_data.action.fcurves
for fc in fcurves:
for keyframe in fc.keyframe_points:
keyframe.interpolation = 'BEZIER'
# Reset transform pivot point
bpy.context.scene.tool_settings.transform_pivot_point = 'MEDIAN_POINT'
# Method 2: Using constraints and empty objects as controllers
else:
# Create empty objects to control the explosion
explosion_control = bpy.data.objects.new("ExplosionControl", None)
explosion_control.empty_display_type = 'SPHERE'
explosion_control.empty_display_size = 0.5
bpy.context.scene.collection.objects.link(explosion_control)
explosion_control.location = center
# Set keyframes for the empty control object
scene.frame_set(start_frame)
explosion_control.scale = (1, 1, 1)
explosion_control.keyframe_insert(data_path="scale", frame=start_frame)
scene.frame_set(end_frame)
explosion_control.scale = (1, 1, 1)
explosion_control.keyframe_insert(data_path="scale", frame=end_frame)
scene.frame_set(explosion_frame)
explosion_control.scale = (explosion_factor, explosion_factor, explosion_factor)
explosion_control.keyframe_insert(data_path="scale", frame=explosion_frame)
# Add constraints to objects
for obj in selected_objects:
# Calculate vector from center to object
direction = obj.location - center
if direction.length > 0:
direction.normalize()
# Create an empty as target for this specific part
part_control = bpy.data.objects.new(f"Control_{obj.name}", None)
part_control.empty_display_type = 'ARROWS'
part_control.empty_display_size = 0.3
bpy.context.scene.collection.objects.link(part_control)
part_control.location = center + (direction * 0.5)
# Parent the control to the explosion control
part_control.parent = explosion_control
# Add copy location constraint to the part
constraint = obj.constraints.new('COPY_LOCATION')
constraint.target = part_control
constraint.use_offset = True
constraint.influence = 0.0
# Animate constraint influence
scene.frame_set(start_frame)
constraint.influence = 0.0
obj.constraints.active.keyframe_insert(data_path="influence", frame=start_frame)
scene.frame_set(end_frame)
constraint.influence = 0.0
obj.constraints.active.keyframe_insert(data_path="influence", frame=end_frame)
scene.frame_set(explosion_frame)
constraint.influence = 1.0
obj.constraints.active.keyframe_insert(data_path="influence", frame=explosion_frame)
# Reset timeline
scene.frame_set(start_frame)
print("Exploded view animation created successfully!")
def set_up_camera_animation(
center,
distance=10.0,
start_frame=1,
explosion_frame=50,
end_frame=100
):
"""
Set up a camera that orbits around the model during the explosion.
Parameters:
- center: Center point to orbit around
- distance: Distance from center
- start_frame, explosion_frame, end_frame: Timeline frames
"""
scene = bpy.context.scene
# Create camera if it doesn't exist
if 'ExplodedViewCamera' not in bpy.data.objects:
cam_data = bpy.data.cameras.new('ExplodedViewCamera')
camera = bpy.data.objects.new('ExplodedViewCamera', cam_data)
bpy.context.scene.collection.objects.link(camera)
else:
camera = bpy.data.objects['ExplodedViewCamera']
# Set as active camera
scene.camera = camera
# Create empty as target
if 'CameraTarget' not in bpy.data.objects:
target = bpy.data.objects.new('CameraTarget', None)
target.empty_display_type = 'CIRCLE'
target.empty_display_size = 0.5
bpy.context.scene.collection.objects.link(target)
else:
target = bpy.data.objects['CameraTarget']
target.location = center
# Position camera
camera.location = (center.x, center.y - distance, center.z + distance * 0.5)
# Add Track To constraint
if not camera.constraints:
constraint = camera.constraints.new('TRACK_TO')
constraint.target = target
constraint.track_axis = 'TRACK_NEGATIVE_Z'
constraint.up_axis = 'UP_Y'
# Animate camera orbiting
scene.frame_set(start_frame)
camera.location = (center.x, center.y - distance, center.z + distance * 0.5)
camera.keyframe_insert(data_path="location", frame=start_frame)
scene.frame_set(explosion_frame)
camera.location = (center.x - distance, center.y, center.z + distance * 0.5)
camera.keyframe_insert(data_path="location", frame=explosion_frame)
scene.frame_set(end_frame)
camera.location = (center.x, center.y - distance, center.z + distance * 0.5)
camera.keyframe_insert(data_path="location", frame=end_frame)
# Reset timeline
scene.frame_set(start_frame)
def main():
"""Main function to run the script"""
# Clear any previous animation data
for obj in bpy.context.selected_objects:
if obj.animation_data:
obj.animation_data_clear()
# Get the center of all selected objects
center = Vector((0, 0, 0))
selected_objects = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
if selected_objects:
for obj in selected_objects:
center += obj.location
center /= len(selected_objects)
else:
print("No objects selected. Please select the model parts.")
return
# Create exploded view animation
create_exploded_view_animation(
start_frame=1,
explosion_frame=50,
end_frame=100,
explosion_factor=3.0,
use_constraints=False # Change to True for constraint-based animation
)
# Set up camera animation
set_up_camera_animation(
center=center,
distance=10.0,
start_frame=1,
explosion_frame=50,
end_frame=100
)
# Set up render settings
bpy.context.scene.render.engine = 'EEVEE' # Faster rendering with Eevee
bpy.context.scene.render.film_transparent = True # Transparent background
print("Exploded view animation setup complete!")
# Run the script
if __name__ == "__main__":
main()
animation is working but this error is coming. Python: Traceback (most recent call last): File "\Text", line 256, in File "\Text", line 249, in main TypeError: bpy_struct: item.attr = val: enum "EEVEE" not found in ('BLENDER_EEVEE', 'BLENDER_WORKBENCH', 'CYCLES')
You're encountering a simple but common error in your Blender Python script. The error occurs because you're trying to use an incorrect enum value for the render engine setting.
The error message indicates that your script is trying to set the render engine to "EEVEE", but this exact string is not in the list of available options[11][14]. According to the error message, the valid options are:
The solution is straightforward - change your code from using 'EEVEE' to 'BLENDER_EEVEE'. Somewhere in your script, you likely have a line like:
bpy.context.scene.render.engine = 'EEVEE' # Incorrect
Change it to:
bpy.context.scene.render.engine = 'BLENDER_EEVEE' # Correct
This is a common mistake when working with Blender's Python API, as the UI might display "Eevee" while the actual enum value in the Python API is "BLENDER_EEVEE"[14].
For future reference, there are several ways to discover the valid values for enum properties in Blender:
Intentionally using an invalid value: If you assign an invalid value, Blender will raise an error that shows all valid options[11].
Using Python to list options: You can create a helper function to show all enum values[14]:
def show_enum_values(obj, attr):
prop = obj.bl_rna.properties[attr]
return [item.identifier for item in prop.enum_items]
# Example usage:
print(show_enum_values(bpy.context.scene.render, 'engine'))
It's worth mentioning that different versions of Blender may have different render engines available. For example, some newer versions might have 'BLENDER_EEVEE_NEXT' as an option[12]. If you're writing scripts that need to work across multiple Blender versions, it's good practice to check for engine availability before setting it.
The error suggests you're working with an animation that's already functioning correctly ("animation is working but this error is coming"). Since the animation works, this error is likely occurring in a part of the code that's trying to set up rendering but isn't critical to the animation itself[6].
When your animation script runs correctly after this fix, you'll be able to render with Eevee, which provides a good balance between quality and speed compared to Cycles or Workbench[10][5].
write full updated script
Here's the complete updated script with the render engine setting fixed:
import bpy
import math
import mathutils
from mathutils import Vector
def create_exploded_view_animation(
start_frame=1,
explosion_frame=50,
end_frame=100,
explosion_factor=2.0,
use_constraints=False
):
"""
Create an exploded view animation for a model.
Parameters:
- start_frame: Frame where animation starts (assembled state)
- explosion_frame: Frame where model is fully exploded
- end_frame: Frame where animation ends (assembled state again)
- explosion_factor: How far the parts should explode outward
- use_constraints: If True, use empty objects and constraints instead of direct keyframing
"""
# Store the selected objects (model parts)
scene = bpy.context.scene
scene.frame_start = start_frame
scene.frame_end = end_frame
selected_objects = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
if not selected_objects:
print("No mesh objects selected. Please select model parts.")
return
# Calculate the center point of all selected objects
center = Vector((0, 0, 0))
for obj in selected_objects:
center += obj.location
center /= len(selected_objects)
# Method 1: Using direct keyframing
if not use_constraints:
# Set initial keyframes (start position)
scene.frame_set(start_frame)
for obj in selected_objects:
obj.keyframe_insert(data_path="location", frame=start_frame)
# Set final keyframes first (end position same as start)
scene.frame_set(end_frame)
for obj in selected_objects:
obj.keyframe_insert(data_path="location", frame=end_frame)
# Set the explosion keyframes
scene.frame_set(explosion_frame)
# Change pivot to 3D cursor for explosion
bpy.context.scene.tool_settings.transform_pivot_point = 'CURSOR'
bpy.context.scene.cursor.location = center
# Move each part away from the center
for obj in selected_objects:
# Calculate direction vector from center to the object
direction = obj.location - center
# Normalize direction and apply explosion factor
if direction.length > 0:
direction.normalize()
# Move the object outward
obj.location = obj.location + (direction * explosion_factor * obj.dimensions.length)
# Insert keyframe for exploded position
obj.keyframe_insert(data_path="location", frame=explosion_frame)
# Set animation curve interpolation to ease in/out
for obj in selected_objects:
if obj.animation_data and obj.animation_data.action:
fcurves = obj.animation_data.action.fcurves
for fc in fcurves:
for keyframe in fc.keyframe_points:
keyframe.interpolation = 'BEZIER'
# Reset transform pivot point
bpy.context.scene.tool_settings.transform_pivot_point = 'MEDIAN_POINT'
# Method 2: Using constraints and empty objects as controllers
else:
# Create empty objects to control the explosion
explosion_control = bpy.data.objects.new("ExplosionControl", None)
explosion_control.empty_display_type = 'SPHERE'
explosion_control.empty_display_size = 0.5
bpy.context.scene.collection.objects.link(explosion_control)
explosion_control.location = center
# Set keyframes for the empty control object
scene.frame_set(start_frame)
explosion_control.scale = (1, 1, 1)
explosion_control.keyframe_insert(data_path="scale", frame=start_frame)
scene.frame_set(end_frame)
explosion_control.scale = (1, 1, 1)
explosion_control.keyframe_insert(data_path="scale", frame=end_frame)
scene.frame_set(explosion_frame)
explosion_control.scale = (explosion_factor, explosion_factor, explosion_factor)
explosion_control.keyframe_insert(data_path="scale", frame=explosion_frame)
# Add constraints to objects
for obj in selected_objects:
# Calculate vector from center to object
direction = obj.location - center
if direction.length > 0:
direction.normalize()
# Create an empty as target for this specific part
part_control = bpy.data.objects.new(f"Control_{obj.name}", None)
part_control.empty_display_type = 'ARROWS'
part_control.empty_display_size = 0.3
bpy.context.scene.collection.objects.link(part_control)
part_control.location = center + (direction * 0.5)
# Parent the control to the explosion control
part_control.parent = explosion_control
# Add copy location constraint to the part
constraint = obj.constraints.new('COPY_LOCATION')
constraint.target = part_control
constraint.use_offset = True
constraint.influence = 0.0
# Animate constraint influence
scene.frame_set(start_frame)
constraint.influence = 0.0
obj.constraints.active.keyframe_insert(data_path="influence", frame=start_frame)
scene.frame_set(end_frame)
constraint.influence = 0.0
obj.constraints.active.keyframe_insert(data_path="influence", frame=end_frame)
scene.frame_set(explosion_frame)
constraint.influence = 1.0
obj.constraints.active.keyframe_insert(data_path="influence", frame=explosion_frame)
# Reset timeline
scene.frame_set(start_frame)
print("Exploded view animation created successfully!")
def set_up_camera_animation(
center,
distance=10.0,
start_frame=1,
explosion_frame=50,
end_frame=100
):
"""
Set up a camera that orbits around the model during the explosion.
Parameters:
- center: Center point to orbit around
- distance: Distance from center
- start_frame, explosion_frame, end_frame: Timeline frames
"""
scene = bpy.context.scene
# Create camera if it doesn't exist
if 'ExplodedViewCamera' not in bpy.data.objects:
cam_data = bpy.data.cameras.new('ExplodedViewCamera')
camera = bpy.data.objects.new('ExplodedViewCamera', cam_data)
bpy.context.scene.collection.objects.link(camera)
else:
camera = bpy.data.objects['ExplodedViewCamera']
# Set as active camera
scene.camera = camera
# Create empty as target
if 'CameraTarget' not in bpy.data.objects:
target = bpy.data.objects.new('CameraTarget', None)
target.empty_display_type = 'CIRCLE'
target.empty_display_size = 0.5
bpy.context.scene.collection.objects.link(target)
else:
target = bpy.data.objects['CameraTarget']
target.location = center
# Position camera
camera.location = (center.x, center.y - distance, center.z + distance * 0.5)
# Add Track To constraint
if not camera.constraints:
constraint = camera.constraints.new('TRACK_TO')
constraint.target = target
constraint.track_axis = 'TRACK_NEGATIVE_Z'
constraint.up_axis = 'UP_Y'
# Animate camera orbiting
scene.frame_set(start_frame)
camera.location = (center.x, center.y - distance, center.z + distance * 0.5)
camera.keyframe_insert(data_path="location", frame=start_frame)
scene.frame_set(explosion_frame)
camera.location = (center.x - distance, center.y, center.z + distance * 0.5)
camera.keyframe_insert(data_path="location", frame=explosion_frame)
scene.frame_set(end_frame)
camera.location = (center.x, center.y - distance, center.z + distance * 0.5)
camera.keyframe_insert(data_path="location", frame=end_frame)
# Reset timeline
scene.frame_set(start_frame)
def main():
"""Main function to run the script"""
# Clear any previous animation data
for obj in bpy.context.selected_objects:
if obj.animation_data:
obj.animation_data_clear()
# Get the center of all selected objects
center = Vector((0, 0, 0))
selected_objects = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
if selected_objects:
for obj in selected_objects:
center += obj.location
center /= len(selected_objects)
else:
print("No objects selected. Please select the model parts.")
return
# Create exploded view animation
create_exploded_view_animation(
start_frame=1,
explosion_frame=50,
end_frame=100,
explosion_factor=3.0,
use_constraints=False # Change to True for constraint-based animation
)
# Set up camera animation
set_up_camera_animation(
center=center,
distance=10.0,
start_frame=1,
explosion_frame=50,
end_frame=100
)
# Set up render settings - CORRECTED LINE
bpy.context.scene.render.engine = 'BLENDER_EEVEE' # Faster rendering with Eevee
bpy.context.scene.render.film_transparent = True # Transparent background
print("Exploded view animation setup complete!")
# Run the script
if __name__ == "__main__":
main()
will it render automatically?
The script as currently written does not automatically start the rendering process. It sets up:
But it doesn't trigger the rendering process or save the output.
If you'd like to add automatic rendering, here's how you can extend the script with a render function:
def setup_and_start_render(
output_path="//exploded_view_animation",
file_format="FFMPEG",
video_codec="H264",
quality=15,
resolution_x=1920,
resolution_y=1080,
fps=30
):
"""
Set up render settings and start rendering the animation.
Parameters:
- output_path: Path to save rendered output
- file_format: Output format (e.g., "FFMPEG" for video, "PNG" for image sequence)
- video_codec: Codec to use if rendering to video
- quality: Render quality (higher is better)
- resolution_x, resolution_y: Output resolution
- fps: Frames per second
"""
scene = bpy.context.scene
# Configure render settings
scene.render.filepath = output_path
scene.render.image_settings.file_format = file_format
# Video settings if using FFMPEG
if file_format == "FFMPEG":
scene.render.ffmpeg.format = "MPEG4"
scene.render.ffmpeg.codec = video_codec
scene.render.ffmpeg.constant_rate_factor = str(quality)
# Set resolution
scene.render.resolution_x = resolution_x
scene.render.resolution_y = resolution_y
scene.render.resolution_percentage = 100
# Set framerate
scene.render.fps = fps
# Start rendering
bpy.ops.render.render(animation=True)
print(f"Rendering complete! Output saved to: {bpy.path.abspath(output_path)}")
Add the function above to your script, before the main() function
Then modify the end of your main() function to include a call to this new function:
def main():
# ... [existing code] ...
# Set up render settings
bpy.context.scene.render.engine = 'BLENDER_EEVEE'
bpy.context.scene.render.film_transparent = True
# Add this line to start rendering automatically
setup_and_start_render(
output_path="//exploded_view_animation", # Relative to .blend file
file_format="FFMPEG", # For video output
resolution_x=1920,
resolution_y=1080
)
print("Exploded view animation setup complete!")
Time Consuming: Rendering can take significant time depending on your scene complexity and computer specs.
write full updated script and add it should automatically select the model present in the scene
Here's the updated Python script that automatically selects the model in your scene and creates an exploded view animation:
import bpy
import math
import mathutils
from mathutils import Vector
def select_all_model_parts():
"""
Automatically select all mesh objects in the scene.
These are assumed to be the parts of the model for the exploded view.
Returns True if at least one mesh was found and selected.
"""
# Deselect all objects first
bpy.ops.object.select_all(action='DESELECT')
# Find all mesh objects
mesh_objects = [obj for obj in bpy.data.objects if obj.type == 'MESH']
if not mesh_objects:
print("No mesh objects found in the scene. Please add a model first.")
return False
# Select all mesh objects
for obj in mesh_objects:
obj.select_set(True)
# Set the first mesh object as active
bpy.context.view_layer.objects.active = mesh_objects
print(f"Selected {len(mesh_objects)} model parts for exploded view animation.")
return True
def create_exploded_view_animation(
start_frame=1,
explosion_frame=50,
end_frame=100,
explosion_factor=2.0,
use_constraints=False
):
"""
Create an exploded view animation for a model.
Parameters:
- start_frame: Frame where animation starts (assembled state)
- explosion_frame: Frame where model is fully exploded
- end_frame: Frame where animation ends (assembled state again)
- explosion_factor: How far the parts should explode outward
- use_constraints: If True, use empty objects and constraints instead of direct keyframing
"""
# Store the selected objects (model parts)
scene = bpy.context.scene
scene.frame_start = start_frame
scene.frame_end = end_frame
selected_objects = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
if not selected_objects:
print("No mesh objects selected. Please select model parts.")
return
# Calculate the center point of all selected objects
center = Vector((0, 0, 0))
for obj in selected_objects:
center += obj.location
center /= len(selected_objects)
# Method 1: Using direct keyframing
if not use_constraints:
# Set initial keyframes (start position)
scene.frame_set(start_frame)
for obj in selected_objects:
obj.keyframe_insert(data_path="location", frame=start_frame)
# Set final keyframes first (end position same as start)
scene.frame_set(end_frame)
for obj in selected_objects:
obj.keyframe_insert(data_path="location", frame=end_frame)
# Set the explosion keyframes
scene.frame_set(explosion_frame)
# Change pivot to 3D cursor for explosion
bpy.context.scene.tool_settings.transform_pivot_point = 'CURSOR'
bpy.context.scene.cursor.location = center
# Move each part away from the center
for obj in selected_objects:
# Calculate direction vector from center to the object
direction = obj.location - center
# Normalize direction and apply explosion factor
if direction.length > 0:
direction.normalize()
# Move the object outward
obj.location = obj.location + (direction * explosion_factor * obj.dimensions.length)
# Insert keyframe for exploded position
obj.keyframe_insert(data_path="location", frame=explosion_frame)
# Set animation curve interpolation to ease in/out
for obj in selected_objects:
if obj.animation_data and obj.animation_data.action:
fcurves = obj.animation_data.action.fcurves
for fc in fcurves:
for keyframe in fc.keyframe_points:
keyframe.interpolation = 'BEZIER'
# Reset transform pivot point
bpy.context.scene.tool_settings.transform_pivot_point = 'MEDIAN_POINT'
# Method 2: Using constraints and empty objects as controllers
else:
# Create empty objects to control the explosion
explosion_control = bpy.data.objects.new("ExplosionControl", None)
explosion_control.empty_display_type = 'SPHERE'
explosion_control.empty_display_size = 0.5
bpy.context.scene.collection.objects.link(explosion_control)
explosion_control.location = center
# Set keyframes for the empty control object
scene.frame_set(start_frame)
explosion_control.scale = (1, 1, 1)
explosion_control.keyframe_insert(data_path="scale", frame=start_frame)
scene.frame_set(end_frame)
explosion_control.scale = (1, 1, 1)
explosion_control.keyframe_insert(data_path="scale", frame=end_frame)
scene.frame_set(explosion_frame)
explosion_control.scale = (explosion_factor, explosion_factor, explosion_factor)
explosion_control.keyframe_insert(data_path="scale", frame=explosion_frame)
# Add constraints to objects
for obj in selected_objects:
# Calculate vector from center to object
direction = obj.location - center
if direction.length > 0:
direction.normalize()
# Create an empty as target for this specific part
part_control = bpy.data.objects.new(f"Control_{obj.name}", None)
part_control.empty_display_type = 'ARROWS'
part_control.empty_display_size = 0.3
bpy.context.scene.collection.objects.link(part_control)
part_control.location = center + (direction * 0.5)
# Parent the control to the explosion control
part_control.parent = explosion_control
# Add copy location constraint to the part
constraint = obj.constraints.new('COPY_LOCATION')
constraint.target = part_control
constraint.use_offset = True
constraint.influence = 0.0
# Animate constraint influence
scene.frame_set(start_frame)
constraint.influence = 0.0
obj.constraints.active.keyframe_insert(data_path="influence", frame=start_frame)
scene.frame_set(end_frame)
constraint.influence = 0.0
obj.constraints.active.keyframe_insert(data_path="influence", frame=end_frame)
scene.frame_set(explosion_frame)
constraint.influence = 1.0
obj.constraints.active.keyframe_insert(data_path="influence", frame=explosion_frame)
# Reset timeline
scene.frame_set(start_frame)
print("Exploded view animation created successfully!")
def set_up_camera_animation(
center,
distance=10.0,
start_frame=1,
explosion_frame=50,
end_frame=100
):
"""
Set up a camera that orbits around the model during the explosion.
Parameters:
- center: Center point to orbit around
- distance: Distance from center
- start_frame, explosion_frame, end_frame: Timeline frames
"""
scene = bpy.context.scene
# Create camera if it doesn't exist
if 'ExplodedViewCamera' not in bpy.data.objects:
cam_data = bpy.data.cameras.new('ExplodedViewCamera')
camera = bpy.data.objects.new('ExplodedViewCamera', cam_data)
bpy.context.scene.collection.objects.link(camera)
else:
camera = bpy.data.objects['ExplodedViewCamera']
# Set as active camera
scene.camera = camera
# Create empty as target
if 'CameraTarget' not in bpy.data.objects:
target = bpy.data.objects.new('CameraTarget', None)
target.empty_display_type = 'CIRCLE'
target.empty_display_size = 0.5
bpy.context.scene.collection.objects.link(target)
else:
target = bpy.data.objects['CameraTarget']
target.location = center
# Position camera
camera.location = (center.x, center.y - distance, center.z + distance * 0.5)
# Add Track To constraint
if not camera.constraints:
constraint = camera.constraints.new('TRACK_TO')
constraint.target = target
constraint.track_axis = 'TRACK_NEGATIVE_Z'
constraint.up_axis = 'UP_Y'
# Animate camera orbiting
scene.frame_set(start_frame)
camera.location = (center.x, center.y - distance, center.z + distance * 0.5)
camera.keyframe_insert(data_path="location", frame=start_frame)
scene.frame_set(explosion_frame)
camera.location = (center.x - distance, center.y, center.z + distance * 0.5)
camera.keyframe_insert(data_path="location", frame=explosion_frame)
scene.frame_set(end_frame)
camera.location = (center.x, center.y - distance, center.z + distance * 0.5)
camera.keyframe_insert(data_path="location", frame=end_frame)
# Reset timeline
scene.frame_set(start_frame)
def setup_and_start_render(
output_path="//exploded_view_animation",
file_format="FFMPEG",
video_codec="H264",
quality=15,
resolution_x=1920,
resolution_y=1080,
fps=30
):
"""
Set up render settings and start rendering the animation.
Parameters:
- output_path: Path to save rendered output
- file_format: Output format (e.g., "FFMPEG" for video, "PNG" for image sequence)
- video_codec: Codec to use if rendering to video
- quality: Render quality (higher is better)
- resolution_x, resolution_y: Output resolution
- fps: Frames per second
"""
scene = bpy.context.scene
# Configure render settings
scene.render.filepath = output_path
scene.render.image_settings.file_format = file_format
# Video settings if using FFMPEG
if file_format == "FFMPEG":
scene.render.ffmpeg.format = "MPEG4"
scene.render.ffmpeg.codec = video_codec
scene.render.ffmpeg.constant_rate_factor = str(quality)
# Set resolution
scene.render.resolution_x = resolution_x
scene.render.resolution_y = resolution_y
scene.render.resolution_percentage = 100
# Set framerate
scene.render.fps = fps
# Start rendering
bpy.ops.render.render(animation=True)
print(f"Rendering complete! Output saved to: {bpy.path.abspath(output_path)}")
def main():
"""Main function to run the script"""
# First, automatically select all mesh objects in the scene
if not select_all_model_parts():
return # Exit if no meshes found
# Clear any previous animation data
for obj in bpy.context.selected_objects:
if obj.animation_data:
obj.animation_data_clear()
# Get the center of all selected objects
center = Vector((0, 0, 0))
selected_objects = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
if selected_objects:
for obj in selected_objects:
center += obj.location
center /= len(selected_objects)
else:
print("No objects selected. Please select the model parts.")
return
# Create exploded view animation
create_exploded_view_animation(
start_frame=1,
explosion_frame=50,
end_frame=100,
explosion_factor=3.0,
use_constraints=False # Change to True for constraint-based animation
)
# Set up camera animation
set_up_camera_animation(
center=center,
distance=10.0,
start_frame=1,
explosion_frame=50,
end_frame=100
)
# Set up render settings - CORRECTED ENGINE NAME
bpy.context.scene.render.engine = 'BLENDER_EEVEE' # Faster rendering with Eevee
bpy.context.scene.render.film_transparent = True # Transparent background
# Uncomment the following lines if you want automatic rendering
# setup_and_start_render(
# output_path="//exploded_view_animation",
# file_format="FFMPEG",
# resolution_x=1920,
# resolution_y=1080
# )
print("Exploded view animation setup complete!")
# Run the script
if __name__ == "__main__":
main()
Python: Traceback (most recent call last): File "\Text", line 341, in File "\Text", line 287, in main File "\Text", line 27, in select_all_model_parts TypeError: BPy_PropertyRNA - Attribute (setattr): LayerObjects.active expected a Object type, not list
The error you're experiencing is occurring in your select_all_model_parts() function in your Blender Python script. The specific error message indicates that you're trying to set a list of objects as the active object, but Blender expects a single object.
TypeError: BPy_PropertyRNA - Attribute (setattr): LayerObjects.active expected a Object type, not list
This error occurs because the line of code is attempting to assign a list of mesh objects to the active property of the view layer's objects. The active property can only accept a single Object instance, not a collection of objects[11][17].
Looking at your traceback, the error is at line 27 in the select_all_model_parts function. You likely have code that looks like this:
# In your select_all_model_parts function, line 27
bpy.context.view_layer.objects.active = mesh_objects # mesh_objects is a list!
The problem is that mesh_objects is a list containing all your selected mesh objects, but when setting the active object, Blender expects just one single object reference[2][5].
Change your code to set just one object from your list as the active object:
# Fix for line 27
if mesh_objects: # Check if the list is not empty
bpy.context.view_layer.objects.active = mesh_objects # Set first mesh object as active
Here's how your complete select_all_model_parts() function should look:
def select_all_model_parts():
"""
Automatically select all mesh objects in the scene.
These are assumed to be the parts of the model for the exploded view.
Returns True if at least one mesh was found and selected.
"""
# Deselect all objects first
bpy.ops.object.select_all(action='DESELECT')
# Find all mesh objects
mesh_objects = [obj for obj in bpy.data.objects if obj.type == 'MESH']
if not mesh_objects:
print("No mesh objects found in the scene. Please add a model first.")
return False
# Select all mesh objects
for obj in mesh_objects:
obj.select_set(True)
# Set the first mesh object as active (FIX HERE)
if mesh_objects:
bpy.context.view_layer.objects.active = mesh_objects
print(f"Selected {len(mesh_objects)} model parts for exploded view animation.")
return True
In Blender, there are two distinct concepts[5][11][18]:
Python: Traceback (most recent call last): File "\Text", line 342, in File "\Text", line 288, in main File "\Text", line 28, in select_all_model_parts TypeError: BPy_PropertyRNA - Attribute (setattr): LayerObjects.active expected a Object type, not list
The error you're encountering is occurring in your exploded view animation script, specifically in the select_all_model_parts() function. Let me explain the problem and provide you with a solution.
TypeError: BPy_PropertyRNA - Attribute (setattr): LayerObjects.active expected a Object type, not list
This error occurs on line 28 of your select_all_model_parts() function because you're trying to assign a list of objects to the active property of Blender's view layer objects[3][5]. However, the active property can only accept a single Object instance, not a collection of objects.
Looking at the traceback, the error is in your select_all_model_parts function, where you likely have code that looks like this:
# In your select_all_model_parts function (line 28)
bpy.context.view_layer.objects.active = mesh_objects # Error: mesh_objects is a list!
The variable mesh_objects is a list containing all your mesh objects, but when setting the active object, Blender expects just one single object reference[2][5].
Change your code to set just the first object from your list as the active object:
def select_all_model_parts():
"""
Automatically select all mesh objects in the scene.
These are assumed to be the parts of the model for the exploded view.
Returns True if at least one mesh was found and selected.
"""
# Deselect all objects first
bpy.ops.object.select_all(action='DESELECT')
# Find all mesh objects
mesh_objects = [obj for obj in bpy.data.objects if obj.type == 'MESH']
if not mesh_objects:
print("No mesh objects found in the scene. Please add a model first.")
return False
# Select all mesh objects
for obj in mesh_objects:
obj.select_set(True)
# Set the first mesh object as active (FIX HERE)
if mesh_objects: # Check if the list is not empty
bpy.context.view_layer.objects.active = mesh_objects # Use to get the first object
print(f"Selected {len(mesh_objects)} model parts for exploded view animation.")
return True
In Blender, there are two distinct concepts[5][11][18]:
obj.select_set(True)Python: Traceback (most recent call last): File "\Text", line 342, in File "\Text", line 288, in main File "\Text", line 28, in select_all_model_parts TypeError: BPy_PropertyRNA - Attribute (setattr): LayerObjects.active expected a Object type, not list
The error you're encountering is happening in your select_all_model_parts() function when trying to set an active object in Blender. Let me explain the problem and provide a solution.
TypeError: BPy_PropertyRNA - Attribute (setattr): LayerObjects.active expected a Object type, not list
This error occurs because you're trying to assign a list of objects to Blender's active property, but this property can only accept a single Object instance[3][12]. The error is occurring on line 28 of your select_all_model_parts function.
Looking at the traceback, the issue is likely in code that looks something like this:
# In your select_all_model_parts function (line 28)
mesh_objects = [obj for obj in bpy.data.objects if obj.type == 'MESH']
# ...
bpy.context.view_layer.objects.active = mesh_objects # ERROR: mesh_objects is a list!
The variable mesh_objects is a list containing all your mesh objects, but when setting the active object, Blender expects just one single object reference[3][4].
def select_all_model_parts():
"""
Automatically select all mesh objects in the scene.
"""
# Deselect all objects first
bpy.ops.object.select_all(action='DESELECT')
# Find all mesh objects
mesh_objects = [obj for obj in bpy.data.objects if obj.type == 'MESH']
if not mesh_objects:
print("No mesh objects found in the scene. Please add a model first.")
return False
# Select all mesh objects
for obj in mesh_objects:
obj.select_set(True)
# Set the first mesh object as active (FIX HERE)
if mesh_objects: # Check if the list is not empty
bpy.context.view_layer.objects.active = mesh_objects # Use index to get first object
print(f"Selected {len(mesh_objects)} model parts for exploded view animation.")
return True
In Blender, there are two distinct concepts[5][11][15]:
obj.select_set(True)view_layer.objects.active = objThe active object is typically highlighted differently in the interface and is used as the primary target for many operations, especially when multiple objects are selected[4][16].
For example, when performing operations like joining meshes, the active object is the one that all other selected objects are joined into[7]. This is why Blender requires exactly one active object, not a list of objects.
Import your model: Use the SketchUp importer or any other importer that preserves separate components[14].
Select all components: Select all the parts of your model that you want to include in the exploded view.
Run the script: Open Blender's Text Editor, paste this script, and click "Run Script"[6][11].
Adjustable parameters:
start_frame, explosion_frame, end_frame, and explosion_factor in the main() function.use_constraints=True if you prefer a constraint-based approach instead of direct keyframing[1][7].This approach is similar to what's shown in the YouTube video by The CG Essentials[14]:
This method uses empty objects and constraints as demonstrated in George Kayesi's tutorial[1][7]:
The script also sets up a camera that orbits around the model during the explosion, making the animation more dynamic[14].
The script provides a complete solution for creating exploded view animations in Blender, combining techniques from various tutorials into a single automated workflow[1][6][11][14].
Fixed the Render Engine Setting: Changed 'EEVEE' to 'BLENDER_EEVEE' in the render settings section to match Blender's API requirements.
Added Error Handling: Added extra checking for animation data existence before accessing fcurves to avoid potential errors if objects don't have animation data.
Import your model: Use any importer that preserves separate components (like the SketchUp importer mentioned in the tutorial).
Select all parts: Select all the components you want to include in the exploded view animation.
Run the script: Open Blender's Text Editor, paste this updated script, and click "Run Script".
Adjustable parameters:
explosion_factor if you want parts to move further apart or closer togetherstart_frame, explosion_frame, and end_frame to control the timinguse_constraints=True if you prefer the constraint-based approachThe script automatically handles:
If you encounter any other errors related to enum values in the future, remember that you can print the available options with:
print([item.identifier for item in bpy.context.scene.render.bl_rna.properties['engine'].enum_items])
This updated script should work correctly with your animation and fix the render engine setting error you encountered.
Background Processing: Your Blender interface will be unresponsive during rendering. For large projects, consider:
# Alternative for background rendering
bpy.ops.render.render(animation=True, write_still=True)
Output Path: The // prefix in the path means it's relative to your .blend file location. Make sure you've saved your file first.
Testing: It's often better to render a short segment first (e.g., 10 frames) to test settings before committing to a full render.
Format Options:
file_format="FFMPEG"file_format="PNG" or "JPEG"Would you like me to provide the complete script with rendering functionality included?
Automatic Model Selection:
select_all_model_parts() function that automatically finds and selects all mesh objects in the scene[1][3][4].Fixed Render Engine Setting:
'EEVEE' to 'BLENDER_EEVEE' to match Blender's API requirements[11].Better Error Handling:
Added Optional Rendering:
setup_and_start_render() function (commented out by default)[10].main().Improved Animation Process:
Open Blender with your model already imported. The model should consist of multiple separate mesh objects that you want to explode.
Run the Script: Open Blender's Text Editor, paste this script, and click "Run Script" or press Alt+P.
Adjust Parameters (optional): You can modify the following in the main() function:
explosion_factor: Controls how far apart the pieces movestart_frame, explosion_frame, and end_frameuse_constraints: Set to True for an alternative animation methodsetup_and_start_render() call if you want automatic renderingThe script will automatically select all mesh objects in your scene, calculate their center point, and create the exploded view animation with camera movement[13][14][16].
obj.select_set(True))view_layer.objects.active = obj)The active object is usually the last one you've clicked on and is highlighted differently in the interface. Many operations in Blender use the active object as the primary target, especially when multiple objects are selected[1][16].
When working with object selection in Blender 2.8+, always use obj.select_set(True) to select objects and view_layer.objects.active = obj to set the active object[2][5][11].
Remember that the active object is tracked per view layer, which is why you need to use view_layer.objects.active[13][14].
If you need to get the list of currently selected objects, use bpy.context.selected_objects[4][10].
To check if your script is working correctly during development, you can print the active object with: print(bpy.context.view_layer.objects.active)[18].
This fix should resolve your error and allow your exploded view animation script to run properly.
view_layer.objects.active = objThe active object is usually the last one you've clicked on and is highlighted differently in the interface. Many operations in Blender use the active object as the primary target, especially when multiple objects are selected[1][16].
Here's the corrected select_all_model_parts() function:
def select_all_model_parts():
"""
Automatically select all mesh objects in the scene.
These are assumed to be the parts of the model for the exploded view.
Returns True if at least one mesh was found and selected.
"""
# Deselect all objects first
bpy.ops.object.select_all(action='DESELECT')
# Find all mesh objects
mesh_objects = [obj for obj in bpy.data.objects if obj.type == 'MESH']
if not mesh_objects:
print("No mesh objects found in the scene. Please add a model first.")
return False
# Select all mesh objects
for obj in mesh_objects:
obj.select_set(True)
# Set the first mesh object as active
if mesh_objects:
bpy.context.view_layer.objects.active = mesh_objects
print(f"Selected {len(mesh_objects)} model parts for exploded view animation.")
return True
This function will correctly:
active property[5][11]After making this change, your exploded view animation script should run without the TypeError.
When working with object selection in Blender 2.8+, always use:
obj.select_set(True) to select objects[4][5][16]view_layer.objects.active = obj to set the active object[13][15][16]To get a list of currently selected objects, use bpy.context.selected_objects[2][5][14]
If you need to check if your script is working correctly, you can print the active object:
print(bpy.context.view_layer.objects.active)
This fix should resolve your error and allow your exploded view animation script to run properly. The key is to remember that while many objects can be selected simultaneously, only one object can be active at any given time.