Attribute generation menu with VEX

calendar_today

17.05.2022

label

VEX, Automation

mouse

19.0

Description

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

1 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.

2 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.

CPP
        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');
}
    

3 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

link

Related articles

favorite

347

label

VEX

Attribute to match across inputs

favorite

232

label

VEX

Sphere Packing / Dart Throwing Algorithm

favorite

258

label

VEX

Deintersecting spheres with Voronoi

favorite

291

label

VEX

Fitting Planes to Point Clouds

favorite

302

label

VEX

How to analyze VEX code

favorite

139

label

VEX

Monte Carlo Geometry Processing