Save 15% On All Single Licences! Loading... GET OFFER

How to Use Python Scripts in BricsCAD BIM

Quick answer: BIMPYTHON queries and manages data from a model within BricsCAD BIM using a .py Python script, anything from simple property lookups to elaborate calculations based on model parameters. BricsCAD doesn’t ship a Python Shell, so prepare scripts in a separate text or code editor. Python itself, along with its standard libraries, is embedded in BricsCAD BIM already, no separate install needed unless your script uses custom packages. Several sample scripts ship with the BricsCAD BIM installer.

Setting Up a Python Script

  1. Import whatever modules your script needs before accessing the API. Standard library modules use import; external ones typically use import as:
import math
import matplotlib.pyplot as plt
  1. Import current_model from the bricscad.bim module, your entry point for querying the model’s BIM objects:
from bricscad.bim import current_model
  1. Query the model. A few example patterns:
# 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)

bricscad.bim.Objects mappers are chainable, for example, finding parts of a roof close to a wall:

# 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)

Or filter using a function statement:

# Filter roof parts longer than 50 project units
def is_long(obj):
    return obj.prop('Length') > 50
roof_parts.filter(is_long)

Export or visualize data in various formats:

# 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)

Executing the Python Script

  1. Open a new or existing BricsCAD file where you want to run the script.
  2. Type BIMPYTHON and press Enter.
  3. In the dialog that appears, select a Python script file (.py) and click Open to run it.
  4. Unless your script exports or displays data externally, BricsCAD reports the output directly in the Command line.

API Reference

Object methods:

bricscad.bim.Objects class (a collection of BIM Objects):

Module-level functions:

bricscad.bim.Plies class: an indexed, sliceable container of Ply objects, supporting __iter__(), __getitem__(index), __getitem__(slice), and __len__().

bricscad.bim.Ply class: an individual ply object, with get_property(prop_name) returning its property value by name.

Frequently Asked Questions

Do I need to install Python separately to use BIMPYTHON? No, Python and its standard libraries are already embedded in BricsCAD BIM; only custom packages need separate installation.

Where do I write and edit my Python scripts? In an external text or code editor, since BricsCAD doesn’t ship its own Python Shell.

How do I find every property available on a BIM object? Use bricscad.bim.list_properties(obj), which returns the full list of available properties for that entity or ply.

Can I chain multiple filtering and query operations together? Yes, bricscad.bim.Objects mappers are chainable, letting you combine filters, parts(), and within_distance() in sequence.

Powered by Full Pelt Ltd