I am currently using CityEngine for a project and need to import a CSV file into CGA rules for application. However, I have encountered issues with CGA rules in CityEngine and have been unable to resolve them. I am reaching out for your assistance.
Below are the requirements for the project:
- I need the CGA rule to successfully read and apply data from the CSV file.
- My CSV file contains 5 parameters (Buildingoffset, Height, ArcadeSetback, Streetoffset, and GreenCoverPercentage) with 75 sample records, as shown in the attached file.
- I would like the CGA rule to randomly select and apply one of the 75 samples.
Currently, no matter how I modify the CGA rules, different parts of the code keep displaying an "unexpected token" error, as shown in the attached image. I am unsure of the source of the issue, so I would like to ask if there are any errors in my CGA rule code or if there is a recommended way to write it.
Here is my current CGA rule code:
const filePath = "75sampling_results.csv"
const data = readStringTable(filePath)
const numSamples = 75 // Our sample range is from row 2 to row 76
// Define attributes
attr Buildingoffset = 0
attr Height = 0
attr ArcadeSetback = 0
attr Streetoffset = 0
attr GreenCoverPercentage = 0
// Read the CSV file and randomly select a sample
@StartRule
Lot -->
randomSelectSample()
// Randomly select a row from the CSV file and set attributes
randomSelectSample -->
setAttributes(rand(1, numSamples) + 1) // Randomly select rows 2 to 76
// Set attributes
setAttributes(index) -->
Buildingoffset = toFloat(data[index][0])
Height = toFloat(data[index][1])
ArcadeSetback = toFloat(data[index][2])
Streetoffset = toFloat(data[index][3])
GreenCoverPercentage = toFloat(data[index][4])
generateBuilding()
// Generate the building using attributes
generateBuilding -->
offset(Buildingoffset)
extrude(Height)
applyArcadeSetback()
applyStreetoffset()
applyGreenCover()
// Apply ArcadeSetback
applyArcadeSetback -->
setback(ArcadeSetback)
// Apply Streetoffset
applyStreetoffset -->
setback(Streetoffset)
// Apply GreenCoverPercentage
applyGreenCover -->
case GreenCoverPercentage > 0:
color(0, GreenCoverPercentage / 100, 0)
extrude(0.1)
else:
nil
No matter how many times I modify and rewrite the rules, I continue to encounter similar issues. I apologize for the inconvenience and would be grateful if you could advise me on where the error might be or how I should structure this CGA rule. Thank you!