【Rhino】【Python】draw main beam ends to theclosest column center

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

  1. Layer Management

    • Finds beam layers (“BEAM LINE::MAIN::”)
    • Identifies column layer (“COLS_PROFILE”)
  2. Geometry Collection

    • Gathers beam lines
    • Extracts column centroids
  3. 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
                   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hmywillstronger

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值