032 – ForEach Subnetwork SOP

A simple way for deleting one random polygon from a group of objects using the ForEach SubNetwork SOP.

First, lets create a box and copy it a few times.

Screen Shot 2016-06-22 at 5.04.55 PM.png

Using the assemble sop I can add a name attribute to each primitive.

Screen Shot 2016-06-22 at 5.10.37 PM

Now let’s loop over the attribute we just created “name” using the forEach sop

Screen Shot 2016-06-22 at 5.07.16 PM

Inside the ForEach sop, I added an attribute wrangle, running over each primitive.

Screen Shot 2016-06-22 at 5.08.03 PM

And with a simple vex script I can delete a polygon of each object.

i@random = rint(fit01(rand(opdigits(@name)), 0, 4));

if (@primnum == @random){
removeprim(geoself(), @primnum, 1);
}

The first line creates an integer with a random number

Here are the functions I’m using to generate a random number to each geometry.

opdigits()
Returns the integer value of the last sequence of digits of a string

rand()
Creates a random number between 0 and 1 from a seed.

fit01()
Takes the value in the range (0, 1) and shifts it to the corresponding value in the new range (nmin, nmax).

rint()
Rounds the number to the closest integer.

The if statement checks if the current primitive is equal to the random number.

Screen Shot 2016-06-22 at 5.08.11 PM

And then inside the if statement, I’m using the removeprim function to delete the current primitive.

Screen Shot 2016-06-22 at 5.08.17 PM

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s