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
-
Module Import : Utilizes
rhinoscriptsyntax
andRhino.Geometry
. -
Function Definition :
select_circles_by_radius
accepts minimum radius, maximum radius, and tolerance. -
Object Iteration: Processes all objects in the document.
-
Circle Identification:
- Converts objects to geometry.
- Checks for curve type and circularity.
-
Circle Information Extraction : Uses
TryGetCircle()
method. -
Radius Filtering: Checks if the radius is within the specified range.
-
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.