Spiral Tool

Create Curve from Spiral/Segments Data

This script imports path data from a CSV file exported by the Anim Toys Spiral or Segments tool and creates a 2D Bezier curve object in Blender.

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

  1. 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

  1. 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.
  2. Open Blender: Open your Blender project.
  3. Open Scripting Tab: Go to the Scripting workspace in Blender.
  4. New Script: Click New to create a new text file in the Text Editor.
  5. Copy & Paste: Copy the Python script code above and paste it into Blender's Text Editor.
  6. 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.
  7. Run Script: Click the Run Script button (play icon) in the Text Editor's header.
  8. 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

« Back to All Blender Scripts