【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.
相关推荐
用户27784491049933 小时前
借助DeepSeek智能生成测试用例:从提示词到Excel表格的全流程实践
人工智能·python
张风捷特烈4 小时前
Flutter 伪3D绘制#03 | 轴测投影原理分析
android·flutter·canvas
JavaEdge在掘金5 小时前
ssl.SSLCertVerificationError报错解决方案
python
我不会编程5556 小时前
Python Cookbook-5.1 对字典排序
开发语言·数据结构·python
李少兄6 小时前
Unirest:优雅的Java HTTP客户端库
java·开发语言·http
老歌老听老掉牙6 小时前
平面旋转与交线投影夹角计算
python·线性代数·平面·sympy
满怀10156 小时前
Python入门(7):模块
python
无名之逆6 小时前
Rust 开发提效神器:lombok-macros 宏库
服务器·开发语言·前端·数据库·后端·python·rust
你觉得2056 小时前
哈尔滨工业大学DeepSeek公开课:探索大模型原理、技术与应用从GPT到DeepSeek|附视频与讲义下载方法
大数据·人工智能·python·gpt·学习·机器学习·aigc
似水এ᭄往昔6 小时前
【C语言】文件操作
c语言·开发语言