Python Wrappers for BricsCAD
Any Python Experts out there want to alpha test Python wrappers for BricsCAD?
Python 3.12 wrappers around BRX, GUI interface is wxPython.
Testers should know their way around the APIs, and know Python.
All open source, https://github.com/CEXT-Dan/PyRx
See the README and README install
v1.1.152 Preview has a binary for BricsCAD V24 pro https://github.com/CEXT-Dan/PyRx/releases
some sample here https://pyarx.blogspot.com/
lots of stuff here https://www.theswamp.org/index.php?board=76.0
Python 3.12 wrappers around BRX, GUI interface is wxPython.
Testers should know their way around the APIs, and know Python.
All open source, https://github.com/CEXT-Dan/PyRx
See the README and README install
v1.1.152 Preview has a binary for BricsCAD V24 pro https://github.com/CEXT-Dan/PyRx/releases
some sample here https://pyarx.blogspot.com/
lots of stuff here https://www.theswamp.org/index.php?board=76.0
0
Comments
-
Here's a sample doing data extraction using pandas
import traceback
import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
import pandas as pd
def PyRxCmd_doit():
try:
filter = [(Db.DxfCode.kDxfStart, "INSERT")]
ssres: tuple[Ed.PromptStatus, Ed.SelectionSet] = Ed.Editor.select(filter)
if ssres[0] != Ed.PromptStatus.eOk:
return
dataMap = {"Layer": [], "Name": [], "QTY": []}
for id in ssres[1].objectIds():
ref = Db.BlockReference(id)
dataMap["Layer"].append(ref.layer())
dataMap["Name"].append(ref.getBlockName())
dataMap["QTY"].append(1)
df = pd.DataFrame(dataMap)
df = df.groupby(["Layer", "Name"],
sort=False, as_index=False).agg({"QTY": "sum"})
with pd.ExcelWriter("e:\\pandas_to_excel.xlsx") as writer:
df.to_excel(writer, sheet_name="sheet1", index=False)
except Exception as err:
traceback.print_exception(err)
0 -
Last sample for inspiration. Import a shape file as polylines using geopandas
import traceback
import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
import geopandas as gp
def makePline(pnts, model, color):
pline = Db.Polyline(pnts)
pline.setColorIndex(color)
model.appendAcDbEntity(pline)
def PyRxCmd_doit():
try:
filePath = "E:\\Municipal_Boundaries_of_Italy_2019\\Com01012019_WGS84.shp"
gdf = gp.read_file(filePath)
db = Db.curDb()
model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite)
#do MultiPolygon first
gdf0 = gdf.loc[gdf.geometry.geometry.type=='MultiPolygon']
for mp in list(gdf0.geometry):
for p in mp.geoms:
makePline(list(p.exterior.coords), model, 4)
gdf1 = gdf.loc[gdf.geometry.geometry.type=='Polygon']
for p in gdf1.geometry:
makePline(list(p.exterior.coords), model, 3)
gdf2 = gdf.loc[gdf.geometry.geometry.type=='LineString']
for p in gdf2.geometry:
makePline(list(p.coords), model, 2)
except Exception as err:
traceback.print_exception(err)0 -
Hi NigelTufnel,
Wow, that's great!
I tested some of your sample scripts, and those worked like a charm!
I will do some more testing with custom scripts as well.
We've exposed some of our BIM properties functions with BIMPYTON
But this is a very nice and useful addition!0 -
Thanks for testing!
I never noticed BIMPYTHON, I’ll have a look! Really, Python is the coolest scripting language, a perfect match for CAD, surprised this hasn’t been done before. Though, I’ve seen a few projects like PyAcad and PyAutoCAD make valiant attempts
My goal is to create the ultimate CAD scripting language. Simple as Lisp, the power of BRX, without the verbosity of .NET
0 -
This sample is cool “Web Scrape to a BricsCAD table”
https://pyarx.blogspot.com/2023/12/web-scrape-to-bricscad-table-using.html
Python is just too much fun.
0