Description

Copy an object to a midpoint:

  1. Select the object to copy
  2. Select base point
  3. Select start point
  4. Select end point
  5. The object is copied to the middle of the line made with steps 2 and 3

See also

MoveHalf script.

Author and license

Script by MLAV.LAND, licensed under the GNU GPL 3 License.

Code

import rhinoscriptsyntax as rs
 
def copy_object_to_midpoint():
    # Step 1: Select the object to copy
    obj = rs.GetObject("Select an object to copy", preselect=True)
    if not obj:
        return
    
    # Step 2: Select a base (reference) point on the object
    base_point = rs.GetPoint("Select a base point on the object")
    if not base_point:
        return
 
    while True:
        # Step 3: Select the start point
        start_point = rs.GetPoint("Pick the start point (or press Enter to finish)")
        if not start_point:
            break
        
        # Step 4: Select the end point
        end_point = rs.GetPoint("Pick the end point", start_point)
        if not end_point:
            break
        
        # Step 5: Compute the middle point between start and end points
        midpoint = rs.PointAdd(start_point, rs.VectorScale(rs.VectorCreate(end_point, start_point), 0.5))
        
        # Step 6: Copy the object so the base point aligns with the midpoint
        move_vector = rs.VectorCreate(midpoint, base_point)
        rs.CopyObject(obj, move_vector)
        
        print("Object copied to the midpoint.")
    
    print("Copying process finished.")
 
# Run the command
copy_object_to_midpoint()