Skip to content

Build Your First Panel ​

In this tutorial, you will copy blendcss into a Blender addon and build a working N-Panel (the right-hand sidebar in Blender's 3D Viewport) that controls the active object's scale, toggles wireframe display, and runs a Blender operator.

Prerequisites ​

  • Blender 4.2+ (Windows x64, Python 3.11 or 3.13)
  • Basic familiarity with creating a Blender Python addon (__init__.py with register() and unregister())

Step 1: Copy blendcss/ into your addon ​

blendcss is designed to be vendored directly inside your addon folder so users do not need to install external packages.

Create a new addon folder and copy the blendcss/ directory into it:

text
my_first_tool/
├── __init__.py
└── blendcss/
    ├── __init__.py
    ├── panel.py
    ├── ui.py
    ├── core/
    ├── widgets/
    └── binaries/

Why keep blendcss/ inside your addon?

Bundling blendcss/ as a local subpackage keeps your addon self-contained and prevents version conflicts with other addons. See Vendor & Package blendcss for multi-panel and Blender Extension setup.

Step 2: Create a minimal panel ​

Open my_first_tool/__init__.py and define a blendcss.Panel subclass with a draw(self, ui, context) method.

python
bl_info = {
    "name": "My First blendcss Tool",
    "author": "Your Name",
    "version": (1, 0, 0),
    "blender": (4, 2, 0),
    "location": "View3D > N-Panel > First Tool",
    "category": "3D View",
}

from . import blendcss


class FirstToolPanel(blendcss.Panel):
    addon_id = "my_first_tool"
    category = "First Tool"
    label = "Object Inspector"

    def draw(self, ui, context):
        obj = context.active_object
        with ui.card(title=obj.name if obj else "No Active Object"):
            ui.label("Select any object to inspect it.")


def register():
    blendcss.register(FirstToolPanel)


def unregister():
    blendcss.unregister(FirstToolPanel)

Key attributes used here:

  • addon_id: A unique identifier for your addon. All panels sharing an addon_id share one isolated GPU manager.
  • category: The tab name in Blender's N-Panel sidebar.
  • label: The header title of the panel.
  • draw(self, ui, context): Called on Blender redraws, just like bpy.types.Panel.draw. You describe your UI with ui builder methods, and blendcss patches changes in place automatically.

Install and enable my_first_tool in Blender, press N in the 3D Viewport, and open the First Tool tab. You will see a Blender-themed card showing the active object's name.

Step 3: Add reactive controls and an operator ​

Now bind controls directly to the active object's RNA properties (Blender's internal data properties such as obj.scale and obj.show_wire) and add an operator button.

Update draw(self, ui, context) in my_first_tool/__init__.py:

python
    def draw(self, ui, context):
        obj = context.active_object

        with ui.card(title=obj.name if obj else "No Active Object"):
            if obj:
                ui.number(
                    "Scale X",
                    bind=(obj, "scale", 0),
                    min_val=0.01,
                    max_val=20.0,
                    step=0.02,
                    precision=3,
                )
                ui.toggle(
                    "Wireframe",
                    subtitle="Show viewport wireframe overlay",
                    bind=(obj, "show_wire"),
                )
                with ui.row(gap=6):
                    ui.operator("object.duplicate", "Duplicate", icon="layers", variant="primary", linked=False)
                    ui.operator("view3d.view_all", "Frame", icon="eye")
            else:
                ui.label("Select an object in the 3D Viewport.")

What you get automatically:

  • ui.number(..., bind=(obj, "scale", 0)): Drag left/right to scrub the value, hold Shift for fine steps, or click to type a math expression such as 1.5 * 2.
  • ui.toggle(..., bind=(obj, "show_wire")): Stays in sync if you change the property from Blender's Properties editor or Python console.
  • ui.operator(...): Automatically runs Blender's poll() check to disable the button when unavailable, passes linked=False as an operator argument, and executes in the right viewport context.

Step 4: Style the panel with CSS ​

Every blendcss.Panel includes default Blender-themed styles (default_styles = True) and live CSS custom properties (--bl-*) that match the user's active Blender Dark or Light theme.

Add a css attribute to FirstToolPanel and apply a custom class to the card and button:

python
PANEL_CSS = """
.inspector-card {
    border-top: 3px var(--bl-accent);
    border-radius: 10px;
    padding: 14px;
}
.hint-text {
    font-size: 11px;
    color: var(--bl-text-muted);
}
"""


class FirstToolPanel(blendcss.Panel):
    addon_id = "my_first_tool"
    category = "First Tool"
    label = "Object Inspector"
    css = PANEL_CSS

    def draw(self, ui, context):
        obj = context.active_object

        with ui.card(title=obj.name if obj else "No Active Object", cls="inspector-card"):
            if obj:
                ui.number("Scale X", bind=(obj, "scale", 0), min_val=0.01, step=0.02, precision=3)
                ui.toggle("Wireframe", subtitle="Viewport wireframe overlay", bind=(obj, "show_wire"))
                with ui.row(gap=6):
                    ui.operator("object.duplicate", "Duplicate", icon="layers", variant="primary", linked=False)
                    ui.operator("view3d.view_all", "Frame", icon="eye")
            else:
                ui.label("Select an object in the 3D Viewport.", cls="hint-text")

Notice how var(--bl-accent) and var(--bl-text-muted) adapt automatically if you switch Blender's theme in Edit → Preferences → Themes.

Next Steps ​

Released under the GNU GPL v3.0 License.