文章目录
Core Technique
The script uses three fundamental techniques:
1. Center Point Detection
def find_closest_point(test_point, target_points, max_distance=1000):
for point in target_points:
distance = rs.Distance(test_point, point)
if distance < min_distance and distance <= max_distance:
min_distance = distance
closest_point = point
- Implements a maximum search radius of 1000 units
- Uses point-to-point distance calculation
- Returns closest point and distance
2. Column Center Extraction
# Get center points of columns
for col in col_objects:
if rs.IsCurve(col) and rs.IsCurveClosed(col):
centroid = rs.CurveAreaCentroid(col)
- Identifies closed curves (column profiles)
- Calculates centroid of each column
- Stores centers for proximity checks
3. Beam Line Adjustment
if line_modified:
old_layer = rs.ObjectLayer(line)
rs.DeleteObject(line)
new_line = rs.AddLine(new_start, new_end)
rs.ObjectLayer(new_line, old_layer)
- Creates new lines instead of modifying existing ones
- Preserves original layer assignments
- Maintains structural relationships
Processing Thread
-
Layer Management
- Finds beam layers (“BEAM LINE::MAIN::”)
- Identifies column layer (“COLS_PROFILE”)
-
Geometry Collection
- Gathers beam lines
- Extracts column centroids
-
Connection Adjustment
- Checks beam endpoints against column centers
- Adjusts endpoints to nearest column
- Creates new adjusted lines
This automation significantly reduces manual adjustment time while ensuring accurate beam-to-column connections.
The script is particularly useful for:
- Large structural models
- Multiple beam-column connections
- Maintaining precise structural connections
- Batch processing of structural elements
overview
import rhinoscriptsyntax as rs
import math
def find_closest_point(test_point, target_points, max_distance=1000):
"""Find the closest point within max_distance"""
closest_point = None
min_distance = max_distance
for point in target_points:
distance = rs.Distance(test_point, point)
if distance < min_distance and distance <= max_distance: # Added explicit distance check
min_distance = distance
closest_point = point
return closest_point, min_distance if closest_point else (None, None)
def adjust_lines_to_columns():
# Get all layers first
all_layers = rs.LayerNames()
beam_layers = [layer for layer in all_layers if layer.startswith("BEAM LINE::MAIN::")]
if not beam_layers:
print("No matching beam line layers found")
return
# Collect all beam lines from matching layers
beam_lines = []
for layer in beam_layers:
objects = rs.ObjectsByLayer(layer)
if objects:
for obj in objects:
if rs.IsCurve(obj):
beam_lines.append(obj)
if not beam_lines:
print("No valid beam lines found in matching layers")
return
# Get all column rectangles
col_objects = rs.ObjectsByLayer("COLS_PROFILE")
if not col_objects:
print("No column profiles found")
return
# Get center points of all columns
column_centers = []
for col in col_objects:
try:
if rs.IsCurve(col) and rs.IsCurveClosed(col):
centroid = rs.CurveAreaCentroid(col)
if centroid:
column_centers.append(centroid[0])
except:
continue
if not column_centers:
print("No valid column centers found")
return
# Process each beam line
adjusted_count = 0
modified_count = 0
rs.EnableRedraw(False)
try:
for line in beam_lines:
try:
if not rs.IsCurve(line):
continue