【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.
相关推荐
llp11103 分钟前
基于java线程池和EasyExcel实现数据异步导入
java·开发语言
四念处茫茫10 分钟前
【C语言系列】深入理解指针(3)
c语言·开发语言·visual studio
I"ll carry you18 分钟前
【Django教程】用户管理系统
python·django
雪芽蓝域zzs19 分钟前
IDEA工具下载、配置和Tomcat配置
android·tomcat·intellij-idea
xueqianliying22 分钟前
Android 定位 获取当前位置 (Kotlin)
android
闲暇部落24 分钟前
多线程详解——Kotlin多线程几种实现方式
android·kotlin·多线程
cuber膜拜1 小时前
jupyter使用 Token 认证登录
ide·python·jupyter
张登杰踩2 小时前
pytorch2.5实例教程
pytorch·python
codists2 小时前
《CPython Internals》阅读笔记:p353-p355
python
Change is good2 小时前
selenium定位元素的方法
python·xpath定位