【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.
相关推荐
千天夜2 分钟前
使用UDP协议传输视频流!(分片、缓存)
python·网络协议·udp·视频流
测试界的酸菜鱼6 分钟前
Python 大数据展示屏实例
大数据·开发语言·python
羊小猪~~10 分钟前
神经网络基础--什么是正向传播??什么是方向传播??
人工智能·pytorch·python·深度学习·神经网络·算法·机器学习
晨曦_子画15 分钟前
编程语言之战:AI 之后的 Kotlin 与 Java
android·java·开发语言·人工智能·kotlin
Black_Friend23 分钟前
关于在VS中使用Qt不同版本报错的问题
开发语言·qt
孤客网络科技工作室37 分钟前
AJAX 全面教程:从基础到高级
android·ajax·okhttp
放飞自我的Coder39 分钟前
【python ROUGE BLEU jiaba.cut NLP常用的指标计算】
python·自然语言处理·bleu·rouge·jieba分词
希言JY1 小时前
C字符串 | 字符串处理函数 | 使用 | 原理 | 实现
c语言·开发语言
残月只会敲键盘1 小时前
php代码审计--常见函数整理
开发语言·php
xianwu5431 小时前
反向代理模块
linux·开发语言·网络·git