Docs
Download

Conditions

Run or draw different nodes depending on a value with If/Else and Switch.

If/Else runs its Then output when Condition is true and its Else output when it's false. Switch does the same for more than two cases. Both work in code (an operator, an event) and in the interface (a panel, a menu), where they decide what gets drawn.

A panel that shows "Mesh tools" because the active object is a mesh: Is Object Type feeds the Condition of an If/Else after the panel's Draw

If/Else

Add Add › Flow › If/Else and link a flow into it, e.g. an operator's Execute or a panel's Draw.

Connect a true/false value to Condition: a checkbox property, a Compare node, Is Object Type, Is in Mode.

Link what should happen when it's true to Then, and what should happen otherwise to Else.

Link what comes next, for both cases, to After.

Then and Else can stay empty. An If/Else with only Then connected is a plain "if".

Socket
Condition (input)A Boolean. Anything else is tested the way Python does: 0, "", an empty list and None count as false
ThenRuns when Condition is true
ElseRuns when it's false
AfterRuns after either branch

Switch

A Switch compares its Value with a list of cases and runs the output of the first case that matches. Default runs when no case matches, and After runs in every case once the branch is done.

  • New Switch nodes have two cases, A and B. Type in a case's field on the node to rename it; the output takes the same name.
  • Add Case at the bottom of the node adds a case, and the X next to a case removes it (with its output and links).
  • The values are compared as text: Value is turned into a string first, so the number 2 matches a case named 2. An enum property's current item ('MESH', 'OBJECT') matches a case with its identifier, MESH.

Use a Switch on an enum property to show different settings for each choice, or on a mode string to react to the mode Blender is in.

In panels and menus

Linked after an interface flow (an orange one, like a panel's Draw or a Row), If/Else and Switch turn orange too and draw only the matching branch. Their outputs connect to interface nodes, and After continues drawing below.

Panels redraw all the time, so the branch follows the condition live: the label in the screenshot changes to "Select a mesh first" as soon as you click a light.

The node takes its kind from the flow linked to its input, or from what its outputs link to while the input is empty. To hide a whole panel or block an operator instead of a part of it, connect the condition to the panel's Is Visible or the operator's Is Available (see Panels and Creating operators).

Values without a flow

To pick one of two values (not two flows), use Switch Data. It has no flow sockets and works wherever a value goes.