Move Objects to Specified Z Coordinate
Rhino Python script for moving selected objects or control points to a specified Z coordinate value.
Features
- Manual input or text object selection for Z value
- Automatic number extraction from text (e.g., “SFL 0.95” → 0.95)
- Remembers last input value as default
- Supports moving objects and control points
- Input unit: meters, processing unit: millimeters
Usage
Input Number
- Run script
- Enter number (e.g., 1.5)
- Select objects to move
Select Text
- Run script
- Click text object containing number
- Select objects to move
Move Control Points
- Select object and enable control point editing (F10)
- Select control points
- Run script
- Enter or select target Z value
Supported Text Formats
SFL 0.95
→ 0.95Level 1.23m
→ 1.23-1.5
→ -1.5Height: 2.8m
→ 2.8
#coding=utf-8
# Move selected objects/control points to specified Z coordinate
# Input unit: meters(m), execution unit: millimeters(mm)
# Supports objects, control points and groups
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
import System.Guid
import re
def extract_number_from_text(text):
"""Extract number from text, supports decimals"""
# Use regex to match numbers (including decimals)
# Matches formats like: 123, 1.23, -1.23, .95, etc.
pattern = r'[-+]?(?:\d+\.?\d*|\.\d+)'
matches = re.findall(pattern, text)
if matches:
# Return the first matched number
try:
return float(matches[0])
except ValueError:
return None
return None
def get_target_z_value():</