1
$\begingroup$

I want to recreate a custom group nodes, which has this specular input (float), via script.

enter image description here

I know that the bl_rna shows the soft_max/min and also the hard_max/min values, but bl_rna is a read-only info.

I have the following source at this moment:

enter image description here

But this won't affect the soft limits, neither the step increase/decrease. Is it possible to create a custom FloatProperty and assign to this input node, changing the step and soft/hard values?

$\endgroup$

2 Answers 2

3
$\begingroup$

I think it's not possible. It looks like the hard caps are not respected for inputs and outputs in shader node sockets. Also, it seems it's not possible to change the caps through the Python API, since those attributes are read-only.

The value validation is obscure, as explained there for instance : https://devtalk.blender.org/t/node-properties-seem-to-miss-range-limit-validation/10129

In Blender FloatProperty and IntProperty have soft and hard limits for values that can be assigned. The soft limits soft_min and soft_max is what the sliders in the UI use by default. The hard limits hard_min and hard_max should be the allowed range of values that can be entered manually or assigned through the Python API. This seems to be true for the properties is the general users interface, however it does not apply to the property of nodes.

However if you test the validation on material nodes, e.g. the Principled BSDF you can assign values that are outside of the range. For example the Metallic property is supposed to have hard min of 0.0 and a hard max of 1.0. These values where retrieved through the RNA.

It’s possible to manually assign values higher than 1.0 in the UI as well as through the Python API.

You do have the possibility to change soft min and soft max using the UI or min_value and max_value with the API, but there is afaik no way to set hard min and max on node sockets. The same goes for the scrubbing step attribute.

$\endgroup$
1
  • $\begingroup$ I noticed that, even setting the max/min_value, the step increase/decrease is too big, being impossible to control, and also the UI doesn't show that blue "fill". I believe that the only way was to set a custom floatProperty, changing the values, but I found no documentation related to how to set that. But like you mentioned, although I am not that worried with hard values, i wish i could change specially the step increase/decrease. $\endgroup$
    – Nakayama
    Jun 14, 2021 at 12:09
1
$\begingroup$

Ok, so I didn't find any answer around, so I am adding mine. I created a custom node socket float node like below:

import bpy
from bpy.props import FloatProperty
from bpy.types import NodeSocketFloat
from bpy.utils import register_class
from bpy.utils import unregister_class

# Custom socket type
class CustomFloatSocket(NodeSocketFloat):
    # Description string
    '''Custom node socket type'''
    bl_idname = 'CustomSocket_FloatType'
    bl_label = "Custom Node Socket"

    # Optional function for drawing the socket input value
    def draw(self, context, layout, node, text):
        if self.is_output or self.is_linked:
            layout.label(text=text)
        else:
            layout.prop(self, "default_value", text=text, slider=True)

    # Socket color
    def draw_color(self, context, node):
        return (1.0, 0.4, 0.216, 0.5)

    default_value: bpy.props.FloatProperty(
        name="CustomFloatSocket",
        description="Custom float socket node with max value of 1.000",
        default=1.000,
        min=0.000,
        max=1.000,
        precision=3,
        step=0.1,
    )

register_class(CustomFloatSocket)

With this, I managed to change the step and the soft values as I wanted.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .