Purpose
This Python script allows you to take the path generated by the Anim Toys Spiral tool or Segments tool in Fusion and recreate it as a 2D Bezier curve in Blender. This curve can then be used for various purposes, such as a motion path for objects or cameras, or as a base for modeling.
Prerequisites
- You must have a CSV file exported from the Anim Toys Spiral tool or Segments tool in Fusion.
Script Code
import bpy
import csv
import math
from mathutils import Vector
# --- User-defined variables ---
csv_filepath = r"C:\pathto\your_spiral_or_segments_data.csv" # Raw string for path
max_distance = 10.0 # Maximum desired extent of the curve from the origin in Blender units
def create_curve_from_csv(filepath, max_dist):
"""Creates a Bezier curve in Blender from path data in a CSV file."""
try:
print(f"Attempting to open CSV file at: {filepath}")
with open(filepath, 'r', newline='') as csvfile_handle:
reader = csv.DictReader(csvfile_handle)
points_data = []
max_abs_coord_val = 0 # Used for scaling
for row_num, row in enumerate(reader):
try:
x_str = row.get('center_point_x', row.get('x'))
y_str = row.get('center_point_y', row.get('y'))
if x_str is None or y_str is None:
print(f"Warning: Row {row_num+1} missing 'center_point_x'/'y' or 'x'/'y' keys. Skipping row: {row}")
continue
x = float(x_str) - 0.5
y = float(y_str) - 0.5
points_data.append((x, y))
max_abs_coord_val = max(max_abs_coord_val, abs(x), abs(y))
except (ValueError, KeyError) as e:
print(f"Error reading row {row_num+1}: {row}. Skipping. Error: {e}")
continue
if not points_data:
print("No valid point data found in the CSV file.")
return
print(f"Extracted {len(points_data)} points. Max absolute coordinate value for scaling: {max_abs_coord_val}")
curve_data = bpy.data.curves.new('AnimToysCurve', type='CURVE')
curve_data.dimensions = '2D'
polyline = curve_data.splines.new('BEZIER')
polyline.bezier_points.add(len(points_data) - 1)
scale_factor = 1.0
if max_abs_coord_val > 1e-6:
scale_factor = max_dist / max_abs_coord_val
else:
print("Warning: Max coordinate value is near zero. Using scale factor of 1.0.")
print(f"Calculated scale factor: {scale_factor}")
for i, (x, y) in enumerate(points_data):
polyline.bezier_points[i].co = Vector((x * scale_factor, y * scale_factor, 0.0))
polyline.bezier_points[i].handle_left_type = 'FREE'
polyline.bezier_points[i].handle_right_type = 'FREE'
polyline.bezier_points[i].handle_left = polyline.bezier_points[i].co.copy()
polyline.bezier_points[i].handle_right = polyline.bezier_points[i].co.copy()
curve_object = bpy.data.objects.new('AnimToysCurveObject', curve_data)
bpy.context.collection.objects.link(curve_object)
print(f"Bezier curve '{curve_object.name}' created successfully from '{filepath}'.")
except FileNotFoundError:
print(f"Error: CSV file not found at '{filepath}'. Please check the path.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
if __name__ == "__main__":
create_curve_from_csv(csv_filepath, max_distance)
How to Use
- Export Data: In Fusion, use the Export Spiral Data button (from Spiral tool) or Export Segments Data button (from Segments tool) to save a
.csv
file. Remember to specify the full path and filename including the.csv
extension. - Open Blender: Open your Blender project.
- Open Scripting Tab: Go to the Scripting workspace in Blender.
- New Script: Click New to create a new text file in the Text Editor.
- Copy & Paste: Copy the Python script code above and paste it into Blender's Text Editor.
- Modify Script:
- Update the
csv_filepath
variable to the correct full path of your exported CSV file. Ensure you use a raw string (r"..."
) or escape backslashes on Windows (e.g.,"C:\\Users\\YourName\\Documents\\data.csv"
). - Adjust the
max_distance
variable. This value determines the maximum extent (in Blender units, typically meters) that the generated curve will spread from the origin. The script scales the imported path so its largest coordinate dimension fits within this distance.
- Update the
- Run Script: Click the Run Script button (play icon) in the Text Editor's header.
- Check Curve: A new 2D Bezier curve object named AnimToysCurveObject (or similar) should appear in your scene, representing the path from your CSV file.
Notes
- CSV Column Names:
- The script expects CSV files from the Spiral tool (or SpiroCat tool) to have columns named
center_point_x
andcenter_point_y
. - For CSV files from the Segments tool, it expects columns named
x
andy
. - The script attempts to read either set of keys, making it compatible with exports from both tools.
- The script expects CSV files from the Spiral tool (or SpiroCat tool) to have columns named
- Scaling: The imported path data (which is typically in a 0-1 normalized space from Fusion) is scaled so that its largest dimension (X or Y extent from the center 0.5,0.5 of the normalized space) fits within the
max_distance
you define in Blender units. - 2D Curve: The script creates a 2D Bezier curve (Z-coordinates are 0).
- Handles: The script sets very short, free handles for the Bezier points to closely follow the dense point data from the CSV. You can adjust this behavior (e.g., by setting handle types to AUTO or VECTOR) if needed.
- This script provides a foundation. You might want to extend it, for example, to create 3D curves if your CSV contains Z data, or to apply modifiers like a Bevel for thickness directly.