For ease of display, all input and output sockets on nodes, both shader and geometry, can be hidden from the user. Hiding unused node inputs and outputs may be necessary to simplify the visual perception of the node tree, which can be very large and complex and does not need to be overloaded with unnecessary information.
To control the display of input and output sockets on nodes, each socket has the “hide” property of boolean type. If its value is False, the input/output socket is visually displayed on the node. If the value is True, the socket is hidden and becomes invisible.
For example, let’s hide all inputs and outputs on some node, for example, on the Principled BSDF.
A pointer to the node itself:
1 2 3 |
bsdf = bpy.context.object.active_material.node_tree.nodes.active # <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF.001") at 0x000002A0C660A260> |
Loop through all its input sockets and hide them.
1 2 |
for input in bsdf.inputs: input.hide = False |
For convenience, we can not only hide the socket, but invert the value of its “hide” property. In this case, each time the script runs, the input socket will either be hidden if it was displayed, or shown back if it was hidden.
1 2 |
for input in bsdf.inputs: input.hide = not input.hide |
The same applies to output sockets.
1 2 |
for output in bsdf.outputs: output.hide = not output.hide |
For Geometry Nodes, everything works exactly the same.
For example, do the same operation for the Dial Gizmo node.
1 2 3 |
gizmo = bpy.context.object.modifiers.active.node_group.nodes.active # <bpy_struct, GeometryNodeGizmoDial("Dial Gizmo") at 0x000002A0C660AB20> |
For its input sockets.
1 2 |
for input in gizmo.inputs: input.hide = not input.hide |
And for outputs.
1 2 |
for output in gizmo.outputs: output.hide = not output.hide |
Note that if a socket has a link from another node connected to it, even setting the “hide” property to True will not hide this socket.