BIM + BrxDbProperties and Python.
Playing with the new BrxDbProperties in V25, an attempt to extract some data into pandas
from pyrx_imp import Rx, Ge, Gs, Gi, Db, Ap, Ed, Brx
from collections import defaultdict
import pandas as pd
import traceback
def PyRxCmd_doit1():
try:
# search conditions
bimTypeKey = "Type~BIM"
bimTypeVal = "Column"
data = {"AxisLength~BIM": [], "Space~BIM": [], "Count": []}
ps, ss = Ed.Editor.select([(Db.DxfCode.kDxfStart, "3DSOLID")])
for id in ss.objectIds():
props = set(Brx.DbProperties.listAll(id))
if bimTypeKey in props and Brx.DbProperties.isValid(id, bimTypeKey)[0]:
acval = Brx.DbProperties.getValue(id, bimTypeKey)
if acval.format() != bimTypeVal:
continue
# this could be better
if not Brx.DbProperties.isValid(id, "AxisLength~BIM")[0]:
continue
if not Brx.DbProperties.isValid(id, "Space~BIM")[0]:
continue
data["AxisLength~BIM"].append(
Brx.DbProperties.getValue(id, "AxisLength~BIM").format())
data["Space~BIM"].append(
Brx.DbProperties.getValue(id, "Space~BIM").format())
data["Count"].append(1)
df = pd.DataFrame(data)
gdf = df.groupby(
["AxisLength~BIM", "Space~BIM"], sort=True, as_index=False
).agg({"Count": "sum"})
odf = gdf[["Count", "AxisLength~BIM", "Space~BIM"]]
print(odf)
# write it to exel
# with pd.ExcelWriter("e:\\pandas_to_excel.xlsx") as writer:
# odf.to_excel(writer, sheet_name="sheet1", index=False)
except Exception as err:
traceback.print_exception(err)
2
Comments
-
Thanks for the inspiration! Here's an example using a translation table to auto-classify mechanical components as bim types.
def PyRxCmd_bim_attsync():
try: # Translation table translation_table = { "DIN EN 558 Flanged Angle Valve": "eBimFlowController", "DIN 2605 Elbow Type 10 45 Deg": "eBimFlowSegment", # add more translation pairs to table } # Suchbedingungen bimTypeKey = "Component name~MCAD" print(f"Looking up objects with TypeKey {bimTypeKey}") print("Using translation table") print(translation_table) db = Db.curDb() ids = db.objectIds(Db.BlockReference.desc()) for id in ids: props = set(Brx.DbProperties.listAll(id)) if bimTypeKey in props and Brx.DbProperties.isValid(id, bimTypeKey)[0]: acval = Brx.DbProperties.getValue(id, bimTypeKey) if acval.format() in translation_table: bimElementTypeStr = translation_table[acval.format()] bimElementType = getattr(Bim.BimElementType, bimElementTypeStr) print(f"ID: {id}, Current Classification: {Bim.BimClassification.getClassification(id)}") if Bim.BimClassification.getClassification(id) != bimElementType: Bim.BimClassification.classifyAs(id, bimElementType) print(f"ID: {id} classified as {bimElementTypeStr}") except Exception as err: traceback.print_exception(err)06.12.24: Updated
Db.BlockReference.desc()1


