<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unable to apply CSV file in CGA rules, CGA rules display errors in ArcGIS CityEngine Questions</title>
    <link>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559098#M11477</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/853241"&gt;@Yu_Tung_Lin0&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your question. I looked into the CGA code you provided and found several issues:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Setting attributes needs the &lt;A href="https://doc.arcgis.com/en/cityengine/latest/cga/cga-set.htm" target="_blank"&gt;set operation—ArcGIS CityEngine Resources | Documentation&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;When addressing elements in an array, this is how to use the&amp;nbsp;&lt;A href="https://doc.arcgis.com/en/cityengine/latest/cga/cga-item-operator-function.htm" target="_blank"&gt;index operator—ArcGIS CityEngine Resources | Documentation&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;The rand function returns floats, for addressing first convert to &lt;EM&gt;integer&lt;/EM&gt; using&amp;nbsp;&lt;A href="https://doc.arcgis.com/en/cityengine/latest/cga/cga-rint-function.htm" target="_blank"&gt;rint function—ArcGIS CityEngine Resources | Documentation&lt;/A&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The unexpected token errors are resolved in this version of the&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;setAttributes(index)&lt;/EM&gt; rule above:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;// Set attributes
setAttributes(i) --&amp;gt;
	set(Buildingoffset, float(data[rint(i),0]))
	set(Height, float(data[rint(i),1]))
	set(ArcadeSetback, float(data[rint(i),2]))
	set(Streetoffset, float(data[rint(i),3]))
	set(GreenCoverPercentage, float(data[rint(i),4]))
	generateBuilding()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps you completing your project&amp;nbsp;successfully&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Nov 2024 10:48:09 GMT</pubDate>
    <dc:creator>ThomasFuchs</dc:creator>
    <dc:date>2024-11-15T10:48:09Z</dc:date>
    <item>
      <title>Unable to apply CSV file in CGA rules, CGA rules display errors</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559082#M11476</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Below are the requirements for the project:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I need the CGA rule to successfully read and apply data from the CSV file.&lt;/LI&gt;&lt;LI&gt;My CSV file contains 5 parameters (Buildingoffset, Height, ArcadeSetback, Streetoffset, and GreenCoverPercentage) with 75 sample records, as shown in the attached file.&lt;/LI&gt;&lt;LI&gt;I would like the CGA rule to randomly select and apply one of the 75 samples.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Here is my current CGA rule code:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080"&gt;const filePath = "75sampling_results.csv"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;const data = readStringTable(filePath) &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;const numSamples = 75 // Our sample range is from row 2 to row 76&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080"&gt;// Define attributes&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;attr Buildingoffset = 0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;attr Height = 0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;attr ArcadeSetback = 0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;attr Streetoffset = 0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;attr GreenCoverPercentage = 0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080"&gt;// Read the CSV file and randomly select a sample&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;@StartRule&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;Lot --&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;randomSelectSample()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080"&gt;// Randomly select a row from the CSV file and set attributes&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;randomSelectSample --&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;setAttributes(rand(1, numSamples) + 1) // Randomly select rows 2 to 76&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080"&gt;// Set attributes&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;setAttributes(index) --&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;Buildingoffset = toFloat(data[index][0])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;Height = toFloat(data[index][1])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;ArcadeSetback = toFloat(data[index][2])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;Streetoffset = toFloat(data[index][3])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;GreenCoverPercentage = toFloat(data[index][4])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;generateBuilding()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080"&gt;// Generate the building using attributes&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;generateBuilding --&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;offset(Buildingoffset)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;extrude(Height)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;applyArcadeSetback()&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;applyStreetoffset()&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;applyGreenCover()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080"&gt;// Apply ArcadeSetback&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;applyArcadeSetback --&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;setback(ArcadeSetback)&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;// Apply Streetoffset&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;applyStreetoffset --&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;setback(Streetoffset)&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;// Apply GreenCoverPercentage&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;applyGreenCover --&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;case GreenCoverPercentage &amp;gt; 0:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;color(0, GreenCoverPercentage / 100, 0)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;extrude(0.1)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;else:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;nil&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 09:02:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559082#M11476</guid>
      <dc:creator>Yu_Tung_Lin0</dc:creator>
      <dc:date>2024-11-15T09:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to apply CSV file in CGA rules, CGA rules display errors</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559098#M11477</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/853241"&gt;@Yu_Tung_Lin0&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your question. I looked into the CGA code you provided and found several issues:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Setting attributes needs the &lt;A href="https://doc.arcgis.com/en/cityengine/latest/cga/cga-set.htm" target="_blank"&gt;set operation—ArcGIS CityEngine Resources | Documentation&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;When addressing elements in an array, this is how to use the&amp;nbsp;&lt;A href="https://doc.arcgis.com/en/cityengine/latest/cga/cga-item-operator-function.htm" target="_blank"&gt;index operator—ArcGIS CityEngine Resources | Documentation&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;The rand function returns floats, for addressing first convert to &lt;EM&gt;integer&lt;/EM&gt; using&amp;nbsp;&lt;A href="https://doc.arcgis.com/en/cityengine/latest/cga/cga-rint-function.htm" target="_blank"&gt;rint function—ArcGIS CityEngine Resources | Documentation&lt;/A&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The unexpected token errors are resolved in this version of the&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;setAttributes(index)&lt;/EM&gt; rule above:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;// Set attributes
setAttributes(i) --&amp;gt;
	set(Buildingoffset, float(data[rint(i),0]))
	set(Height, float(data[rint(i),1]))
	set(ArcadeSetback, float(data[rint(i),2]))
	set(Streetoffset, float(data[rint(i),3]))
	set(GreenCoverPercentage, float(data[rint(i),4]))
	generateBuilding()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps you completing your project&amp;nbsp;successfully&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 10:48:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559098#M11477</guid>
      <dc:creator>ThomasFuchs</dc:creator>
      <dc:date>2024-11-15T10:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to apply CSV file in CGA rules, CGA rules display errors</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559261#M11479</link>
      <description>&lt;P&gt;Thank you very much for your prompt response. After rewriting the rules according to your suggestions, the issues with setAttributes have been resolved. However, new unexpected token errors have appeared in the applyStreetoffset and applyGreenCover sections (as shown in the attached image). Could you please advise how these parts of the CGA rules should be modified?&lt;/P&gt;&lt;P&gt;Here are the CGA rules code that have errors:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080"&gt;// Apply Streetoffset&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;applyStreetoffset --&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;setback(Streetoffset)&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;// Apply GreenCoverPercentage&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;applyGreenCover --&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;case GreenCoverPercentage &amp;gt; 0:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;color(0, GreenCoverPercentage / 100, 0)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;extrude(0.1)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;else:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008080"&gt;nil&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I apologize for asking again, and thank you so much for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 17:35:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559261#M11479</guid>
      <dc:creator>Yu_Tung_Lin0</dc:creator>
      <dc:date>2024-11-15T17:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to apply CSV file in CGA rules, CGA rules display errors</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559460#M11480</link>
      <description>&lt;P&gt;I have modified the code you provided, but I believe it might not produce the intended result. The current outcome is due to applying setbacks simultaneously to a single parcel. It is better to use the 'selector' to distinguish areas for the offset and setback commands, and apply setbacks step by step while progressing through the rule for each area.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="desert_0-1731735329705.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/119709iAD636EE3C1553A47/image-size/medium?v=v2&amp;amp;px=400" role="button" title="desert_0-1731735329705.png" alt="desert_0-1731735329705.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;const data = readStringTable("data/75sampling_results.csv")
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 --&amp;gt;
randomSelectSample()

// Randomly select a row from the CSV file and set attributes
randomSelectSample --&amp;gt;
setAttributes(rand(1, numSamples) + 1) // Randomly select rows 2 to 76

// Set attributes
setAttributes(i) --&amp;gt;
set(Buildingoffset,float(data[rint(i),0]))
set(Height, float(data[rint(i),1]))
set(ArcadeSetback, float(data[rint(i),2]))
set(Streetoffset, float(data[rint(i),3]))
set(GreenCoverPercentage, float(data[rint(i),4]))
generateBuilding

// Generate the building using attributes
generateBuilding --&amp;gt;
	offset(Buildingoffset)
	extrude(Height)
	print(Height)
	applyArcadeSetback
	applyStreetoffset
	applyGreenCover

// Apply ArcadeSetback
applyArcadeSetback --&amp;gt;
setback(ArcadeSetback){all = ARC_offset. | remainder : X.}

applyStreetoffset --&amp;gt;
setback(Streetoffset){all = ST_offset. | remainder : X.}

// Apply GreenCoverPercentage
applyGreenCover --&amp;gt;
case GreenCoverPercentage &amp;gt; 0:
color(0, GreenCoverPercentage / 100, 0)
extrude(0.1)
else: NIL
&lt;/LI-CODE&gt;&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 05:43:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559460#M11480</guid>
      <dc:creator>desert</dc:creator>
      <dc:date>2024-11-16T05:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to apply CSV file in CGA rules, CGA rules display errors</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559698#M11482</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363945"&gt;@desert&lt;/a&gt;&amp;nbsp;for providing more help.&lt;/P&gt;
&lt;P&gt;At this point it also needs to be mentioned, that those "unexpected token" errors generally occur when using a wrong syntax in a previous code statement. It is always a good idea to consult the online help. Usually there are also code snippets provided that show common usage.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ThomasFuchs_0-1731943335413.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/119752i9A4AE767D13782EC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ThomasFuchs_0-1731943335413.png" alt="ThomasFuchs_0-1731943335413.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Also the code completion feature (hit &amp;lt;ctrl + space&amp;gt; while typing) can help finding the right syntax.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ThomasFuchs_1-1731943712936.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/119753iE2C7137064D8154D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ThomasFuchs_1-1731943712936.png" alt="ThomasFuchs_1-1731943712936.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://doc.arcgis.com/en/cityengine/latest/cga/cga-setback.htm" target="_blank"&gt;setback operation—ArcGIS CityEngine Resources | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 15:29:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/unable-to-apply-csv-file-in-cga-rules-cga-rules/m-p/1559698#M11482</guid>
      <dc:creator>ThomasFuchs</dc:creator>
      <dc:date>2024-11-18T15:29:16Z</dc:date>
    </item>
  </channel>
</rss>

