Attribute generation menu with VEX

calendar_today

17.05.2022

label

VEX, Automation

mouse

19.0

1 Introduction

Let's extend an attribute wrangle to a comfortable control node for generating lots of attributes with random values between specific ranges.

2 Menu setup

Generate an attribute wrangle and set it to run over detail.

Edit the parameter interface, drag over a folder, name it "attrib" and set its type to "multiparm block". Drag a string and a float vector2 parameter underneath the folder. Rename the string to name and the vector2 to range and hit Accept.

After clicking on the plus button a few times, parameter fields should appear as shown on the screenshot.

3 VEX Code

Enter the following code in the same detail wrangle. It will create a new detail attribute for every name parameter in the block and a random value between the minimum and maximum range values based on the seed value.

int seed = chi('seed');

for(int i = 1; i <= ch('attrib'); i++){
    string num = itoa(i);
    float n = rand(seed, i);
    
    string name = ch('name' + num);
    vector2 range = chu('range' + num);
    
    float value = lerp(range[0], range[1], n);
    setdetailattrib(0, name, value, 'set');
}

4 Dictionary

After the detail attributes have been used to drive your setup, you might want to wrap them up into a dictionary so all random values get stored. For this append an attribute adjust dictionary-node, assign a suitable attribute name, leave the attribute class at detail and activate import attributes and enter *.

download

Downloads

smart_display

Videos

Custom Attribute Menu with Multiparm Blocks and VEX – Houdini Tutorial