【Rhino】【Python】Select Circular Objects Within Specified Radius Range

Rhino Python Script: Selecting Circles by Radius

Overview

This Python script for Rhinoceros (Rhino) selects circular objects within a specified radius range.

Key Features

  • Scans all objects in Rhino
  • Identifies circular objects
  • Filters circles based on user-defined radius range
  • Selects matching circular objects

Code Analysis

python 复制代码
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg

def select_circles_by_radius(min_radius=0, max_radius=float('inf'), tolerance=0.01):
    all_objects = rs.AllObjects()
    circles = []
    
    for obj in all_objects:
        try:
            geometry = rs.coercegeometry(obj)
            if isinstance(geometry, rg.Curve) and geometry.IsCircle(tolerance):
                success, circle = geometry.TryGetCircle()
                if success:
                    radius = circle.Radius
                    if min_radius <= radius <= max_radius:
                        circles.append(obj)
        except Exception as e:
            print("Error processing object:", str(e))
            continue
    
    if circles:
        rs.SelectObjects(circles)
        print("Selected {} circles with radius between {} and {}.".format(len(circles), min_radius, max_radius))
    else:
        print("No circles found with radius between {} and {}.".format(min_radius, max_radius))

# Usage example
select_circles_by_radius(5, 10)

Implementation Details

  1. Module Import : Utilizes rhinoscriptsyntax and Rhino.Geometry.

  2. Function Definition : select_circles_by_radius accepts minimum radius, maximum radius, and tolerance.

  3. Object Iteration: Processes all objects in the document.

  4. Circle Identification:

    • Converts objects to geometry.
    • Checks for curve type and circularity.
  5. Circle Information Extraction : Uses TryGetCircle() method.

  6. Radius Filtering: Checks if the radius is within the specified range.

  7. Object Selection : Selects filtered circles using rs.SelectObjects().

python 复制代码
select_circles_by_radius(5, 10)  # Selects circles with radii between 5 and 10

Applications

  • Selecting circular holes or columns of specific sizes.
  • Locating circular elements in complex models.
  • Quality control for circular object dimensions.
相关推荐
Swift社区7 分钟前
在 Swift 中实现字符串分割问题:以字典中的单词构造句子
开发语言·ios·swift
没头脑的ht9 分钟前
Swift内存访问冲突
开发语言·ios·swift
没头脑的ht12 分钟前
Swift闭包的本质
开发语言·ios·swift
wjs202414 分钟前
Swift 数组
开发语言
stm 学习ing1 小时前
FPGA 第十讲 避免latch的产生
c语言·开发语言·单片机·嵌入式硬件·fpga开发·fpga
Estar.Lee1 小时前
查手机号归属地免费API接口教程
android·网络·后端·网络协议·tcp/ip·oneapi
温辉_xh2 小时前
uiautomator案例
android
湫ccc2 小时前
《Python基础》之字符串格式化输出
开发语言·python
mqiqe3 小时前
Python MySQL通过Binlog 获取变更记录 恢复数据
开发语言·python·mysql