欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > 【Rhino】【Python】Create a series of Blocks according to Value of object Property

【Rhino】【Python】Create a series of Blocks according to Value of object Property

2024/11/30 8:36:01 来源:https://blog.csdn.net/hmywillstronger/article/details/144013675  浏览:    关键词:【Rhino】【Python】Create a series of Blocks according to Value of object Property

文章目录

    • 1. Complete Code Display
    • 2. Detailed Code Analysis
      • 2.1 Import and Setup
      • 2.2 Function Structure and Initial Setup
      • 2.3 Object Collection and Filtering
      • 2.4 Story Management System
      • 2.5 Locating Point Processing
      • 2.6 Object Organization by Story
      • 2.7 Block Creation System
      • 2.8 Block Assembly and Placement
    • 3. Key Technical Concepts
      • 3.1 Data Organization
      • 3.2 Error Handling
      • 3.3 Automation Features
    • 4. Best Practices Demonstrated
    • 5. Practical Applications
      • 5.1 BIM Integration
      • 5.2 Drawing Management
    • 6. Further Development Possibilities
    • 7. Conclusion

在这里插入图片描述
在这里插入图片描述

1. Complete Code Display

#coding=utf-8import rhinoscriptsyntax as rs
import scriptcontext as sc
import datetimedef create_blocks_by_story():timestamp = datetime.datetime.now().strftime("%Y%m%d")parent_layer = "01 STR. LINE LAYOUT(FOR FEM)"if not rs.IsLayer(parent_layer):rs.AddLayer(parent_layer)# Get all objectsall_objects = rs.AllObjects()etabs_objects = []locating_points = []# Filter Etabs objectsfor obj in all_objects:obj_name = rs.ObjectName(obj)if obj_name and obj_name.startswith("Etabs"):if obj_name == "Etabs locating":locating_points.append(obj)else:etabs_objects.append(obj)if not etabs_objects:print("No objects with names starting with 'Etabs' found")returnstory_dict = {}story_base_points = {}story_locating_points = {}# Process locating pointsif locating_points:for point in locating_points:if rs.ObjectType(point) == 1:story_value = rs.GetUserText(point, "Story")if story_value:point_coord = rs.PointCoordinates(point)story_base_points[story_value] = (0, 0, 0)story_locating_points[story_value] = point# Sort objects by storyfor obj in etabs_objects:story_value = rs.GetUserText(obj, "Story")if story_value:if story_value not in story_dict:story_dict[story_value] = []story_dict[story_value].append(obj)# Create blocks for each storyfor story, objs in story_dict.items():if len(objs) > 0:if story not in story_base_points:print("Warning: No base point found for Story {}".format(story))continueblock_name = "Story_" + str(story)layer_name = "{}::{}_{}_{}".format(parent_layer, block_name, timestamp, "block")if not rs.IsLayer(layer_name):rs.AddLayer(layer_name)copied_objs = [rs.CopyObject(obj) for obj in objs]if story in story_locating_points:copied_objs.append(rs.CopyObject(story_locating_points[story]))base_point = story_base_points[story]block_ref = rs.AddBlock(copied_objs, base_point, block_name, True)instance = rs.InsertBlock(block_ref, base_point)rs.ObjectLayer(instance, layer_name)print("Created block '{}' with {} objects on layer '{}'".format(block_name, len(copied_objs), layer_name))if etabs_objects:rs.DeleteObjects(etabs_objects)print("All original objects have been deleted")create_blocks_by_story()

2. Detailed Code Analysis

2.1 Import and Setup

#coding=utf-8
import rhinoscriptsyntax as rs
import scriptcontext as sc
import datetime
  • UTF-8 encoding for international character support
  • Essential Rhino scripting tools
  • Datetime for timestamp generation

2.2 Function Structure and Initial Setup

def create_blocks_by_story():timestamp = datetime.datetime.now().strftime("%Y%m%d")parent_layer = "01 STR. LINE LAYOUT(FOR FEM)"

Purpose:

  • Creates unique timestamps for versioning
  • Establishes parent layer structure

2.3 Object Collection and Filtering

all_objects = rs.AllObjects()
etabs_objects = []
locating_points = []for obj in all_objects:obj_name = rs.ObjectName(obj)if obj_name and obj_name.startswith("Etabs"):if obj_name == "Etabs locating":locating_points.append(obj)else:etabs_objects.append(obj)

Features:

  • Collects all Rhino objects
  • Separates locating points from other Etabs objects
  • Implements smart filtering system

2.4 Story Management System

story_dict = {}
story_base_points = {}
story_locating_points = {}

Data Structure:

  • story_dict: Maps stories to their objects
  • story_base_points: Stores reference points
  • story_locating_points: Manages locating points per story

2.5 Locating Point Processing

if locating_points:for point in locating_points:if rs.ObjectType(point) == 1:  # Point object checkstory_value = rs.GetUserText(point, "Story")if story_value:point_coord = rs.PointCoordinates(point)story_base_points[story_value] = (0, 0, 0)story_locating_points[story_value] = point

Key Features:

  • Validates point objects
  • Extracts story information
  • Sets up reference coordinate system

2.6 Object Organization by Story

for obj in etabs_objects:story_value = rs.GetUserText(obj, "Story")if story_value:if story_value not in story_dict:story_dict[story_value] = []story_dict[story_value].append(obj)

Process:

  • Reads story metadata
  • Groups objects by story level
  • Creates organized data structure

2.7 Block Creation System

for story, objs in story_dict.items():if len(objs) > 0:block_name = "Story_" + str(story)layer_name = "{}::{}_{}_{}".format(parent_layer, block_name, timestamp, "block")

Features:

  • Dynamic block naming
  • Hierarchical layer structure
  • Timestamp integration

2.8 Block Assembly and Placement

copied_objs = [rs.CopyObject(obj) for obj in objs]
if story in story_locating_points:copied_objs.append(rs.CopyObject(story_locating_points[story]))base_point = story_base_points[story]
block_ref = rs.AddBlock(copied_objs, base_point, block_name, True)
instance = rs.InsertBlock(block_ref, base_point)

Process:

  • Object duplication
  • Locating point integration
  • Block creation and insertion

3. Key Technical Concepts

3.1 Data Organization

- Hierarchical data structures
- Story-based object grouping
- Reference point management

3.2 Error Handling

- Object existence verification
- Layer validation
- Story assignment checking

3.3 Automation Features

- Automatic layer creation
- Dynamic block naming
- Timestamp-based versioning

4. Best Practices Demonstrated

  1. Code Organization:
- Clear function structure
- Logical data flow
- Modular design
  1. Error Prevention:
- Input validation
- Existence checks
- Clear error messages
  1. Performance Optimization:
- Batch processing
- Efficient data structures
- Minimal object manipulation

5. Practical Applications

5.1 BIM Integration

- Etabs model organization
- Story-based structural analysis
- Reference point management

5.2 Drawing Management

- Automated block creation
- Layer organization
- Version control

6. Further Development Possibilities

  1. Enhanced Error Handling:
try:# Add more specific error checkingif not validate_story_data(story_value):raise ValueError("Invalid story data")
except Exception as e:print(f"Error processing story: {e}")
  1. Advanced Filtering:
def filter_objects_by_criteria(objects, criteria):return [obj for obj in objects if meets_criteria(obj, criteria)]
  1. Progress Reporting:
def report_progress(current, total):print(f"Processing: {current}/{total} complete")

7. Conclusion

This code represents a sophisticated approach to:

  • Building Information Modeling (BIM) automation
  • Structural engineering workflows
  • Drawing management systems
  • Version control implementation

Understanding these concepts helps in developing more advanced architectural and engineering automation tools.

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com