Python Scripting API - Script Examples
Warning
Use of the API is an advanced feature and should only be used by users with a working knowledge of both Tribli and the Python scripting language. In rare cases, use of the API may lead to corruption of the project data, so be sure to save any work prior to use. Operations completed through the scripting API cannot be undone.
Note
The Tribli scripting API was completely rewritten in Tribli version 5.5.0. As such, this documentation is applicable only to Tribli versions 5.5.0 and later.
Create New Model and Export Columns Loads
This script creates a new Tribli model with 6 levels and sets up a simple structure with columns, walls and slabs. It then calculates the tributary areas and column loads before exporting an excel load summary.
import shapely.geometry as sp
#Create a new model with 6 levels
app.new_model(6)
#Set the height of the lower-most level to zero
app.model.levels[0].height = 0
#Create geometry for slab at all levels
slab_geom = sp.Polygon([(0,0),(20000,0),(20000,20000),(0,20000)])
#Create geometry for all columns
column_coords = [(2000,2000),(10000,2000),(18000,2000),
(2000,10000),(18000,10000),
(2000,18000),(10000,18000),(18000,18000)]
columns_pts = [sp.Point(*cd) for cd in column_coords]
#Create geometry for core walls
w1_geom = sp.LineString([(6000,7000),(14000,7000)])
w2_geom = sp.LineString([(6000,7000),(6000,13000)])
w3_geom = sp.LineString([(14000,7000),(14000,13000)])
w4_geom = sp.LineString([(6000,13000),(14000,13000)])
#Create geometry for loads
#Create area load geom by buffering out the slab geometry by a meter.
#This is not strictly necessary, but makes distiguishing the slab and load easier later on
area_load_geom = slab_geom.buffer(1000)
#Create the line load by buffering the slab geometry inwards by 100mm and converting to a LineString
line_load_geom = sp.LineString(slab_geom.buffer(-100).exterior)
#Add object to all levels
for i in range(1,6):
lev = app.model.levels[i]
#Add Slab
slab = lev.add_slab(slab_geom)
slab.thickness = 230 #Set slab thickness in mm
#Add columns
for pt in columns_pts:
col = lev.add_column(pt)
col.D = 350 #mm
col.B = 350 #mm
#Add core walls
lev.add_wall(w1_geom)
lev.add_wall(w2_geom)
lev.add_wall(w3_geom)
lev.add_wall(w4_geom)
#Add area loads and set loading
aload = lev.add_area_load(area_load_geom)
aload.dead = 1 #kPa
aload.r_live = 1.5 #kPa
#Add facade line load
lload = lev.add_line_load(line_load_geom)
lload.dead = 2.5 #kN/m
#Generate column and wall chains
app.model.generate_chains()
#Generate tributary areas
app.model.generate_tributary_areas()
#Calculate column loads
app.model.calculate_loads()
#Export column base loads to an excel spreadsheet
fpath = "" #Fill in your desired file path here
app.model.export_column_base_loads(fpath)
Plugin to Create Custom Excel Summary
This script works on an existing Tribli model and creates a custom excel summary spreadsheet. If saved as a '.plg' file in Tribli's plugin directory, this file can be executed as a plugin directly from the file menu.
#Import openpyxl for exporting spreadsheet summary
import openpyxl
#Calculate column loads prior to exporting summary
app.model.calculate_loads()
#Create new excel spreadsheet
wb = openpyxl.Workbook()
ws = wb.active #get the active worksheet
#Set worksheet title
ws.title="Load List"
#Append column titles to worksheet
ws.append(["Chain","Level","Size","f'c (MPa)","ULS Load (kN)"])
#Iterate through all columns and add data to spreadsheet
for level in app.model.levels:
for col in level.columns:
#Get axial loads with factor of safety
loads = col.get_axial_loads(True)
#Generate the column size description
if col.rect: #column is rectangular
size = f"{col.D}x{col.B}"
else: #column is circular
size = f"{col.D} Diam."
#Export data to spreadsheet
ws.append([col.chain_name, level.name, size, col.fc, loads['ULS']])
#Request a save path from the user
#By default this function assumes a .xlsx file so no need to pass any args
fname = app.get_save_filepath()
#Exit the script if the user does not select a file path
#this line uses the built-in 'end_script' function provided by Tribli
if not fname: end_script()
#Save the spreadsheet
wb.save(fname)