Random box, Iterative processq

random
grasshopper
python
unhandled
iterations

(M Meshkinkiya) #1

Hi everyone,

I am trying to make an iterative run, each time modifying the geometry in Grasshopper i.e. creating “ n ” different samples of a series of boxes, where the random properties is assigned to the box’s height.

I need to read a CSV file consisting of the “ n ” values (i.e. different heights), and each time extract one height and assign it to the box in an iterative process.

From the previous discussions, I understood how to read the CSV file with Python and split the rows. Yet, I am still stuck when it comes to iterative runs.
Ps: I tried to upload *.csv file but i couldn’t, therefore i put the *.txt version of that.

ForForum_Random Geometry.gh (15.1 KB)Rand1.txt (366 Bytes)


(David Rutten) #2

I’m confused about this. In what sense is it supposed to be iterative? Is human intervention required/desired between consecutive iterations?


(David Rutten) #3

Your data file consist of a bunch of lines, each with three values. Are those point coordinates? Are those to be interpreted as the width, depth and height of each box?


(M Meshkinkiya) #4

Dear Rutten,

In this project I try to consider random height for some boxes and this repeat to create n samples for the next part of my job which is uncertainty analysis in Urban area.

The plan (x,y) of boxes in different samples remain same and the random height are provided in CSV file. The CSV file contain three column where each column refer to the height of one box in *.gh file and length of each column refer to number of samples…

I am looking for a way to feed the “Height” properties of “RecBox” component with the random way that I explain.

Hopefully this will be more clear.


(David Rutten) #5

I’m still confused, but you’re saying the columns of numbers are not coordinates, each column represents a collection of different heights for a specific box, and you have three boxes in total. Am I correct so far?

The location and width and depth of the boxes are specified elsewhere, this file only deals with the height of each box?

You want Grasshopper to read in the first row of numbers, assign those numbers as height values to three boxes, and then… do something with those boxes? Once whatever it is you want to do has finished you want to read in the next row of values, and repeat. If so, that’s tricky because GH doesn’t work in such an iterative fashion.

You can use a slider to index a specific row in the file and instate the boxes associated with those values. Or you can read all rows and create all possible box families at the same time (but separated into different branches of a datatree). But do-this-wait-for-it-to-complete-then-do-something-else is not an approach that comes naturally to GH.


(M Meshkinkiya) #6

Dear Rutten,

As you noticed I am looking for a row by row process,

Actually I am new in Grashopper and as I fond with slider I can run my simulation for the specific row at time.
Also I don’t know how I can feed all the rows to RecBox? Should I create the separate component for each n sample?


(M Meshkinkiya) #7

What about coding with Python? Since I knew Python more than GH :slight_smile:

If I create the geometry through Python in a loop:

*Create first sample geometry

  • Assign the random height
  • Do the next calculations
  • Save the results
  • Return to next sample

#8

I doubt you need a loop at all. See this thread:


boxes.gh (18.1 KB)


(David Rutten) #9

Yeah, you can index each row after you load the file like so: index_by_row.gh (10.8 KB)

If you remove the indexing bit, you can do all boxes (all rows) at once. The three boxes will be stored in individual lists, and each row will result in a different list within the same tree: all_at_once.gh (16.2 KB)


(M Meshkinkiya) #10

Dear Rutten

Many thanks for your concern and rapid reply. I try re-do your suggestion, I did not understand why you used the “Num” component in your file.

Actually I have more question about this activities:

Previously I found the attached *.gh file to run several simulation in batch mode, Same as here, I need to automated running Radiation map simulation for different iterations where each time it vary with height of boxes. However, the “Repeat” component ask for a text (“tn”) as the variable to change in each run. The height properties in RecBox is a domain. I am wondering if there is a way to send this property to “Repeat” component.

BatchRun_Height.gh (35.6 KB)


(M Meshkinkiya) #11

Dear Oster

Thanks for very interesting solution of randomizing without using loop. Actually I need to access to value of Height as a variable to change the condition of my simulation for next step which is Radiation map.


(David Rutten) #12

The file contains text data, since it is supposed to represent number data, I prefer to convert the data to actual numbers as soon as it makes sense.


(M Meshkinkiya) #13

Many thanks, I got it, here I attached a txt file since i could not attached here a csv file of data. So need to use of Num component