BIMPYTHON
BIMPYTHON命令使您能够使用合适的.py Python脚本在CSCAD 草图快手中查询和管理模型中的数据。
Python 脚本可以像获取对象和 BIM 实体的数量和相关属性一样简单,也可以像基于可用模型参数实现一系列计算一样复杂。
CSCAD不附带Python Shell,因此需要在文本或代码编辑器应用程序中准备脚本。
Python 编程语言及其标准库嵌入在 CSCAD 草图快手 中,因此除非您有希望在脚本中使用的自定义包和库,否则您无需单独安装它们。
CSCAD 草图快手安装程序中提供了几个Python脚本示例。
如果它们不是 Python 标准库的一部分,请确保事先单独安装它们。
您可以“导入”标准模块,例如数学,并“导入”外部模块,例如 Pyplot,它是 Matplotlib 包中的函数集合:
import math
import matplotlib.pyplot as plt
从cscad 模块导入current_model:
from cscad.bim import current_model
# Display info about the lengths of walls in the model
lengths = [wall.prop('Length') for wall in current_model().filter(Type='Wall')]
print(f'wall lengths. max: {max(lengths)}, avg: {sum(lengths)/len(lengths)}')
# Create a selection and print the objects
current_model().filter(Type='Wall', IsExternal=True).select()
for wall in bim_model.filter(Type='Wall', IsExternal=True, Length=max(lengths)):
print(wall)
cscad.bim.Objects的映射器是可链接的。这是获取靠近墙壁的屋顶部分的示例:
# Get all parts of roof within 40cm range of all walls
roof_parts = current_model().filter(Type='Roof').parts()
roof_parts_close_to_wall = current_model().filter(Type='Wall').within_distance(40, 'cm', search_range=roof_parts)
而这是要过滤的函数语句的示例:
# Filter roof parts longer than 50 project units
def is_long(obj):
return obj.prop('Length') > 50
roof_parts.filter(is_long)
您还可以以各种格式导出和显示数据:
# create a dictionary list
wall_info = [
{ 'Handle': wall.get_property('Handle'),
'Length': wall.get_property('Length'),
'Height': wall.get_property('Height')
} for wall in current_model().filter(Type='Wall')]
# export to .json
import json
file = open('path/to/file.json', 'w+')
file.write(json.dumps(wall_info, indent=4))
file.close()
# plotting a histogram
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame(wall_info)
df.hist();
plt.show()
# export to .csv
df.to_csv(r'path/to/file.csv', index = False, header=True)
有关CSCAD API及其各种类的更多信息,请访问下面的API章节。
类和语法
get_property(prop_name)
返回具有给定名称的对象的属性值。
set_property(prop_name,value)
设置属性名称的值 (prop_name)。
distance_to( other_obj, units='mm', distance_mode='exact' )
parts()
返回此对象的子元素。
parent()
与 parts() 相反,返回此子元素的父对象。
plies()
返回关联的 Plies
可迭代对象。
within_distance( distance, units='mm', distance_mode='exact', search_range=bim_model )
openings()
返回此对象的关联开口。
spaces()
返回此对象的关联空格。
bounding_elements()
返回此(空格)对象的关联边界元素。
select()
将对象添加到所选内容。
deselect()
从选择中删除对象。
__eq__() 和 __hash__()
使对象可与例如 python 集或字典进行互操作。
class cscad.bim.Objects
定义 CSCAD 草图快手 对象的集合
cscad.bim.list_properties(obj)
返回传递的实体或层的可用属性的列表。
cscad.bim.current_model()
返回活动文档的模型空间中的对象。
类 cscad.bim.Plies
层对象的索引、可切片容器。
__iter__()
__getitem__( 索引 )
__getitem__(切片)
__len__()
类 cscad.bim.Ply
单个层物体。
get_property(prop_name)
返回具有给定名称的 Ply 对象的属性值。