read from csv file and loop through list

922
2
11-08-2017 03:12 PM
awei
by
New Contributor III

I'm looking to populate my scene by runtime generating points and assign them with tree objects. A sample tree data looks like this:

Here is my first try. 

HEIGHT=57.17676
Init-->

scatter(surface, 20, gaussian) { TREE }
scatter(surface, 10, gaussian) { TREE }
scatter(surface, 10, gaussian) { TREE }

TREE -->
alignScopeToAxes(y)
s(0,HEIGHT,0)
i(getAssetPath)
center(xz)
Tree.

getAssetPath = ( "assets/Plants/QuakingAspen/QuakingAspen_Model_0.obj" )

So as a first step, I would want to have a set of lists (species, height, number of trees etc.), so that my TREE function and scatter function can loop through all of them, unlike above, where I manually type in each entry. Because I have thousands of entries like this. 

And the ultimate goal is to directly read the csv file. I went through 3D vegetation with lumenRT rules, https://www.arcgis.com/home/item.html?id=0fd3bbe496c14844968011332f9f39b7, and seems they just typed in all the species name, height, etc to the cga files, so I have no idea how to do this. 

Any help with the following two steps is much appreciated!

@Chris Wilkins  Brooks Patrick, Gert Van MarenThomas Fuchs, Cheryl Lau

Tags (2)
0 Kudos
2 Replies
CherylLau
Esri Regular Contributor

Sorry, there is no function in cga to read a csv file.  One workaround would be to write a python script that reads your data file and writes cga string lists.  Then, you access your data in cga using the cga string list functions.  If you only need to do this once (i.e. your data won't change), instead of a Python script, you can also manually reformat each column of your data into the cga string list format using a bunch of find/replace operations.

From the cga help page:

Stringlists are a series of strings stored inside one string. The elements are separated by a semicolon (";"). The data type is "string", thus it is not any real type of array as used in other scripting languages.

The functions listItem() and listIndex() and listSize() are probably useful in accessing the data in a list.

listItem 

listIndex 

listSize 

0 Kudos
awei
by
New Contributor III

Thank you! I worked this out

0 Kudos