Bind Data & Operators
This guide covers how to connect blendcss widgets to Blender RNA properties (such as obj.scale or scene.render.fps), Python dictionaries, callables, and Blender operators.
Bind numeric properties
Use ui.number(...) with bind= to create a drag-scrubbable numeric field with two-way sync and inline math editing.
Supported bind= targets
| Target format | Example | Use case |
|---|---|---|
(object, "prop") | (obj, "pass_index") | Scalar Blender RNA property or Python attribute |
(object, "prop", index) | (obj, "scale", 0) | Vector element (location, scale, rotation_euler) |
(dict, "key") | (self.state, "roughness") | Local Python dictionary state |
(callable, "prop") or (callable, "prop", index) | (lambda: bpy.context.active_object, "scale", 0) | Dynamic target evaluated on every sync |
ui.number(
"Rotation Z",
bind=(lambda: bpy.context.active_object, "rotation_euler", 2),
is_rotation=True, # Displays degrees in UI, stores radians in Blender
unit="°",
step=0.5,
precision=1,
)Built-in user interactions on every bound number field:
- Drag horizontally to scrub the value.
- Hold
Shiftwhile dragging for fine precision. - Hold
Ctrlwhile dragging to snap to clean increments. - Click to type a value or math expression such as
1.5 * 2,pi / 2, or45 deg(evaluated safely via Python's AST).
Bind toggles, tabs, and choices
Boolean switches
ui.toggle(
"Wireframe",
subtitle="Viewport overlay",
bind=(obj, "show_wire"),
on_change=lambda val: print("Wireframe:", val),
)Segmented tabs and choice chips
Both ui.tabs(...) and ui.choice(...) accept either a {value: label} mapping or a list of (value, label) pairs:
ui.tabs(
{"transform": "Transform", "shader": "Shader", "export": "Export"},
bind=(self.state, "active_tab"),
)
ui.choice(
[("LOW", "Low"), ("MED", "Medium"), ("HIGH", "High")],
bind=(self.state, "quality"),
)Bind reactive text labels and badges
For retained-mode panels (build()) or HTML templates, bind text directly to a property or callable:
ui.label(bind=(lambda: bpy.context.active_object, "name"), default="No Selection")
ui.badge(bind=lambda: f"{len(bpy.context.scene.objects)} objects")Bind Blender operators
Use ui.operator(...) to wire a button directly to any Blender operator.
ui.operator(
"object.duplicate", # Also accepts "OBJECT_OT_duplicate" or bpy.ops.object.duplicate
"Duplicate Object", # Optional: defaults to Blender's RNA operator name
icon="layers",
variant="primary",
linked=False, # Extra kwargs are passed directly as operator properties
)Automatic poll() disabling and context overrides
When an operator is bound through blendcss:
poll()sync:blendcssevaluatesop.poll()on redraws and toggles the.is-disabledCSS class automatically when the operator cannot run.- Region
temp_override: Clicks in an N-Panel (UIregion) are automatically executed with abpy.context.temp_override(...)targeting the matchingWINDOWregion (such asVIEW_3D), so viewport operators likeview3d.view_allwork out of the box.
Dynamic operator properties and callbacks
Pass a callable to props= when operator arguments depend on live state, and use on_done / on_error to react to execution results:
ui.operator(
"mesh.primitive_cube_add",
"Add Scaled Cube",
props=lambda: {"size": self.state["cube_size"]},
on_done=lambda result: print("Finished:", result),
on_error=lambda exc: print("Failed:", exc),
)Override the target space or execution context
ui.operator(
"render.render",
"Render Still",
exec_ctx="INVOKE_DEFAULT", # or "EXEC_DEFAULT"
context_override="VIEW_3D", # "AUTO" (default), a space_type string, a dict, or False
undo=True,
)Bindings in raw HTML templates
If you use raw HTML templates instead of UIBuilder, call the binding methods on doc inside on_mount(self, doc):
def on_mount(self, doc):
doc.bind_number("scale_x_val", lambda: bpy.context.active_object, "scale", index=0, hit_id="scale_x_box")
doc.bind_toggle("wire_switch", lambda: bpy.context.active_object, "show_wire")
doc.bind_choice({"tab_a": "a", "tab_b": "b"}, self.state, "active_tab")
doc.bind_text("obj_name", lambda: bpy.context.active_object, "name", default="None")
doc.bind_operator("dup_btn", "object.duplicate", linked=False)See the Bindings & Operators Reference for every parameter and helper function.