Customizer
Customizer containers
The PythonSCAD-only Customizer class keeps parameter values in an explicit
mapping instead of creating global variables. Pass that mapping to modeling
functions just like any other configuration object:
from pythonscad import *
params = Customizer()
base = params.group("Base parameters")
base.add_parameter("diameter", 10, description="Plate diameter")
base.add_parameter("thickness", 3, range=(1, 10, 0.1))
def baseplate(params):
return cylinder(
d=params["diameter"],
h=params["thickness"],
)
show(baseplate(params))
Customizer is a read-only mapping. Customizer.add_parameter() returns the
current effective value as well as storing it in the mapping, so the return
value can also be captured in a local variable:
Use params.group("Tab title") to obtain a cached group view. Parameters added
through that view appear on the corresponding Customizer tab, while all values
remain available through the root params mapping. Parameter names must be
unique across all groups and Customizer instances in one design.
The GUI discovers container parameters when the Python design is evaluated. Run a new design once with F5 or F6 to populate the Customizer panel; subsequent widget changes participate in automatic previews normally.
The module-level add_parameter() function below remains available unchanged
for existing designs. Unlike Customizer.add_parameter(), its legacy default
behavior may create a global variable with the registered name.
add_parameter
Add a parameter that appears in the PythonSCAD Customizer GUI. Users can modify these parameters through the GUI without editing code.
Syntax:
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
string | — | Parameter name (displayed in the GUI) |
default |
any | — | Default value (type determines the widget: int, float, bool, string, list) |
description |
string | "" |
Help text shown in the customizer |
group |
string | "Parameters" |
Tab name for organizing parameters |
range |
range or tuple | None |
Min/max for slider widgets |
step |
float | None |
Step increment for spinbox widgets |
max_length |
int | None |
Maximum string length |
options |
list or dict | None |
Dropdown menu options |
Returns: The current value of the parameter (either the default or the user-modified value).
Basic Usage
The parameter type is inferred from the default value:
Slider
Use range to create a slider widget:
Step (Spinbox)
Use step for a spinbox without a slider:
Dropdown
Use options for a dropdown menu:
Groups
Organize parameters into tabs using group:
from pythonscad import *
width = add_parameter("width", 10, group="Dimensions")
height = add_parameter("height", 20, group="Dimensions")
color = add_parameter("color", "red", group="Appearance")
# Special groups
debug = add_parameter("debug", False, group="Hidden") # not shown in UI
units = add_parameter("units", "mm", group="Global") # appears on all tabs
Description
Add help text with description:
max_length
Limit string input length:
Vectors
Vector parameters (lists) support constraints applied to all elements: