RCT Help Documentation
Home
  • Getting Started
  • Script Metadata
  • Custom UI
  • Core API
  • Chart Class
  • Data Classes
  • Examples
  • Best Practices
Plugin Store
  • 简体中文
  • English
Home
  • Getting Started
  • Script Metadata
  • Custom UI
  • Core API
  • Chart Class
  • Data Classes
  • Examples
  • Best Practices
Plugin Store
  • 简体中文
  • English
  • API Reference

    • Home
    • Getting Started
    • Script Metadata
    • Custom UI Dialog
    • Core API
    • Chart Class
    • Data Classes
    • Example Scripts
    • Best Practices

Core API

The RCT API provides a set of core functions for interacting with the RCT editor and manipulating chart data.

Function List

  • get_current_chart() - Get the currently edited chart
  • save_current_chart() - Save chart to the editor
  • load_chart_from_file() - Load chart from file
  • save_chart_to_file() - Save chart to file

get_current_chart()

Get the chart currently being edited from the RCT editor.

Syntax

from rct_api import get_current_chart

chart = get_current_chart()

Return Value

  • Success: Returns a Chart object
  • Failure: Returns None

Example

from rct_api import get_current_chart

def main():
    chart = get_current_chart()
    if chart:
        print(f"Chart version: {chart.version}")
        print(f"Number of notes: {len(chart.notes)}")
        print(f"Number of BPMs: {len(chart.bpm)}")
    else:
        print("Error: Unable to get chart")

if __name__ == "__main__":
    main()

Notes

IMPORTANT

Always check if the return value is None! If no chart is open in the editor, this function returns None, and direct access will cause the script to crash.

  • This function retrieves live data from the editor
  • After modifications, call save_current_chart() to save changes

save_current_chart()

Save the modified chart back to the RCT editor.

Syntax

from rct_api import save_current_chart

save_current_chart(chart)

Parameters

ParameterTypeDescription
chartChartModified chart object

Return Value

None

Example

from rct_api import get_current_chart, save_current_chart

def main():
    chart = get_current_chart()
    if not chart:
        print("Error: Unable to get chart")
        return
    
    # Modify the chart
    chart.shift_time(1000)  # Delay by 1 second
    
    # Save to editor
    save_current_chart(chart)
    print("Chart saved")

if __name__ == "__main__":
    main()

Notes

  • It's recommended to call chart.sort() before saving to ensure notes are in correct order
  • This operation directly modifies the chart in the editor
  • Cannot be undone, backup is recommended

load_chart_from_file()

Load chart from file (does not affect the chart in the editor).

Syntax

from rct_api import load_chart_from_file

chart = load_chart_from_file(path)

Parameters

ParameterTypeDescription
pathstrPath to the chart file

Return Value

  • Success: Returns a Chart object
  • Failure: Raises an exception

Example

from rct_api import load_chart_from_file

def main():
    try:
        chart = load_chart_from_file("charts/example.txt")
        print(f"Loaded successfully: {len(chart.notes)} notes")
    except Exception as e:
        print(f"Loading failed: {e}")

if __name__ == "__main__":
    main()

Use Cases

  • Batch processing multiple chart files
  • Comparing different versions of charts
  • Generating new charts from template files

save_chart_to_file()

Save chart to file.

Syntax

from rct_api import save_chart_to_file

save_chart_to_file(chart, path)

Parameters

ParameterTypeDescription
chartChartChart object to save
pathstrOutput file path

Return Value

None

Example

from rct_api import get_current_chart, save_chart_to_file

def main():
    chart = get_current_chart()
    if not chart:
        print("Error: Unable to get chart")
        return
    
    # Save to file
    output_path = "output/modified_chart.txt"
    save_chart_to_file(chart, output_path)
    print(f"Chart saved to: {output_path}")

if __name__ == "__main__":
    main()

Use Cases

  • Export processed charts
  • Create chart backups
  • Batch generate chart files

Complete Workflow Example

The following example demonstrates how to combine these core functions:

# Description: Complete chart processing workflow

from rct_api import (
    get_current_chart,
    save_current_chart,
    load_chart_from_file,
    save_chart_to_file
)

def main():
    # 1. Get chart from editor
    chart = get_current_chart()
    if not chart:
        print("Error: Unable to get chart")
        return
    
    print(f"Original note count: {len(chart.notes)}")
    
    # 2. Process the chart
    chart.filter_notes_by_time(1000, 10000)
    chart.shift_time(500)
    chart.sort()
    
    print(f"Processed note count: {len(chart.notes)}")
    
    # 3. Save to editor
    save_current_chart(chart)
    print("Chart updated in editor")
    
    # 4. Also export to file
    save_chart_to_file(chart, "output/processed.txt")
    print("Chart exported to file")

if __name__ == "__main__":
    main()
Prev
Custom UI Dialog
Next
Chart Class