【Python】【Stair】Move Objects to Specified Z Coordinate

发布于:2025-06-05 ⋅ 阅读:(19) ⋅ 点赞:(0)

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

  1. Run script
  2. Enter number (e.g., 1.5)
  3. Select objects to move

Select Text

  1. Run script
  2. Click text object containing number
  3. Select objects to move

Move Control Points

  1. Select object and enable control point editing (F10)
  2. Select control points
  3. Run script
  4. Enter or select target Z value

Supported Text Formats

  • SFL 0.95 → 0.95
  • Level 1.23m → 1.23
  • -1.5 → -1.5
  • Height: 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():</

网站公告

今日签到

点亮在社区的每一天
去签到