Customizer
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: