Linking CSV Data to Dependent Dropdowns in CalcTree
Learn how to connect a CSV file to dynamic, dependent dropdown parameters in CalcTree using Python for structured data filtering and selection.
This guide walks you through how to read structured data from a CSV file and build dependent dropdowns in CalcTree using Python and page Parameters. The pattern is commonly used in workflows that require a selection of section or material type and then extracting specific properties for the selection for use in calculations.
1. Load and Structure Your Data
Upload your CSV file (e.g. CT - Standard Steel Section Capacity - DB.csv
) using the Files tab, then read it into a structured format using pandas. Learn more here.
Once this is complete, create a new code source, and add the below code.
import pandas as pd
def read_csv(csv):
return pd.read_csv(ct.page_files[csv])
section_db = read_csv("CT - Standard Steel Section Capacity - DB.csv") \
.astype('object') \
.fillna("") \
.to_dict("records")
This loads your CSV into a list of dictionaries (records
) that are easy to filter by field name.
2. Apply the Two-Step Filter
2.1 Extract Primary Filter Options
In the same code source get the unique values from a primary column (e.g. "Type"
):
type_list = list({row["Type"] for row in section_db})
2.2 Create page dropdown list
Under the code source in the RHS panel, navigate to the type_list
parameter and insert to page. Then in the settings for this parameter, set the visibility to 'list'. Name your parameter something like pg_type_list
.
2.3 Filter the Secondary Options Based on type_list Selection
Filter the list of available "Section"
values based on the currently selected "Section Type"
.
section_list = list({
row["Section"] for row in section_db if row["Type"] == pg_type_list.upper()
})
Make sure the "Type" name matches the parameter name you set, in this case, pg_type_list
.
2.4 Repeat step 2.2 for the new dependant list
Under the code source in the RHS panel, navigate to the section_list
parameter and insert to page. Then in the settings for this parameter, set the visibility to 'list'. Name your parameter something like pg_type_list
.
3. Use the Selected Section in Your Logic
Once the user has made a selection, extract the full row from the database and use its fields in your calculation.
selected_row = next((row for row in section_db if row["Section"] == section_name), {})
depth = float(selected_row.get("Depth", 0))
area = float(selected_row.get("Area", 0))
moment_capacity = float(selected_row.get("M_ult", 0)) / 1000 # Nm → kNm
4. Use the Selected Item in Your Logic
Once a specific section is selected (e.g., "UB 203x102x23"
), use it to retrieve or process further data in a Code Source 3.
Summary
This approach lets you:
Link a CSV database to interactive parameters
Build dependent dropdowns (e.g. section type → section name)
Extract and use structured data in calculations
It’s ideal for any workflow where selections narrow down from a database — like selecting standard parts, profiles, or material specs.
Last updated