Script for copy pate Spline Component

dpotuznik
Sun, 10 Mar 2024 09:47:59 +0000
Pipeline & Plugins

Hi ,

juste a quick tips.
i wanted to copy the spline component from the old cameraRig_Rail to the new CineCameraRig_Rail , so i made a little script.

usage :
select source cameraRigRail
select target cineCameraRigRail
type in cmd line : py yourPath/getReferenceSelectedSpline.py

I think I can work on other tool , you select the actor and the script look if an splineComponent exist

getReferenceSelectedSpline.py

import unreal

# Get the Editor Actor Subsystem
actor_subsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)

# Get the list of currently selected level actors
selected_actors = actor_subsystem.get_selected_level_actors()


# Check if at least two actors are selected (assuming you want to copy from one and paste to another)
if len(selected_actors) >= 2:
    # Assuming the first selected actor is the source and the second is the destination
    source_actor = selected_actors[0]
    target_actor = selected_actors[1]

    # Attempt to find a SplineComponent within each selected actor
    source_spline = source_actor.get_component_by_class(unreal.SplineComponent)
    target_spline = target_actor.get_component_by_class(unreal.SplineComponent)

    if source_spline and target_spline:
        # Clear existing points in the target spline
        target_spline.clear_spline_points(True)

        # Get the number of points in the source spline
        num_points = source_spline.get_number_of_spline_points()

        # Copy each point from the source spline to the target spline
        for point_index in range(num_points):
            # Get location and tangent of the current point in the source spline
            location = source_spline.get_location_at_spline_point(point_index, unreal.SplineCoordinateSpace.WORLD)
            arrival_tangent = source_spline.get_arrive_tangent_at_spline_point(point_index, unreal.SplineCoordinateSpace.WORLD)
            departure_tangent = source_spline.get_leave_tangent_at_spline_point(point_index, unreal.SplineCoordinateSpace.WORLD)

            # Add a new point to the target spline with the copied location and tangent
            target_spline.add_spline_point_at_index(location, point_index, unreal.SplineCoordinateSpace.WORLD, True)
            target_spline.set_tangents_at_spline_point(point_index,arrival_tangent, departure_tangent, unreal.SplineCoordinateSpace.WORLD,True)

        print("Spline points copied successfully from source to target.")
    else:
        print("A SplineComponent could not be found in one of the selected actors.")
else:
    print("Please select at least two actors with SplineComponents in the Unreal Editor.")

3 posts - 3 participants