Description

Move an object to a midpoint:

  1. Select the object to move
  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

CopyHalf script.

Author and license

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

Code

import rhinoscriptsyntax as rs
 
def move_object_to_midpoint():
    # Step 1: Select the object to move
    obj = rs.GetObject("Select an object to move", 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
    
    # Step 3: Select the start point
    start_point = rs.GetPoint("Pick the start point")
    if not start_point:
        return
    
    # Step 4: Select the end point
    end_point = rs.GetPoint("Pick the end point", start_point)
    if not end_point:
        return
    
    # 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: Move the object so the base point aligns with the midpoint
    move_vector = rs.VectorCreate(midpoint, base_point)
    rs.MoveObject(obj, move_vector)
    
    print("Object moved to the midpoint.")
 
# Run the command
move_object_to_midpoint()