<?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: Reading a DBF file and extracting data with Python in City Engine 2019 in ArcGIS CityEngine Questions</title>
    <link>https://community.esri.com/t5/arcgis-cityengine-questions/reading-a-dbf-file-and-extracting-data-with-python/m-p/1037983#M10140</link>
    <description>&lt;P&gt;My Esri/Python experience doesn't extend into CityEngine much, as I only used it for a single project a couple years ago. &lt;A href="https://doc.arcgis.com/en/cityengine/latest/python/python-special-scripts.htm#ESRI_SECTION1_CFFB536DD78E41D98F13EDEAD8FBF2DA" target="_self"&gt;Looking at the docs&lt;/A&gt;, however, it does look like you could get an external module brought in by using the &lt;STRONG&gt;scripting.py&lt;/STRONG&gt; file.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Typical use cases include adding your scripting directory to the system path, or loading your custom modules to the scripting environment.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A href="https://doc.arcgis.com/en/cityengine/2019.0/tutorials/tutorial-10-python-scripting.htm" target="_self"&gt;Tutorial 10&lt;/A&gt; goes a step further and gives a concrete example:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;To extend scripting.py, complete the following steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a new file scripting.py in your CityEngine workspace using the file browser of your operating system.&lt;/LI&gt;&lt;LI&gt;Add the following lines to automatically map your helper script at startup:&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;import sys&lt;BR /&gt;&lt;BR /&gt;sys.path.append({PATH_TO_YOUR_SCRIPTS_DIRECTORY})&lt;BR /&gt;// e.g. sys.path.append("C:\user\CityEngine\MyProject\scripts")&lt;BR /&gt;import myHelpers&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I would presume that the path being appended could as easily point to a module somewhere.&lt;/P&gt;&lt;P&gt;Side note: have you checked out the python module &lt;A href="https://github.com/Toblerity/Fiona" target="_self"&gt;Fiona&lt;/A&gt;? It's fantastic for working with SHPs and DBFs.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Mar 2021 12:21:13 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2021-03-18T12:21:13Z</dc:date>
    <item>
      <title>Reading a DBF file and extracting data with Python in City Engine 2019</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/reading-a-dbf-file-and-extracting-data-with-python/m-p/1037935#M10138</link>
      <description>&lt;P&gt;I am trying to use Python in City Engine 2019 to read the DBF file of an SHP that is imported into City Engine&lt;/P&gt;&lt;P&gt;I tried to install the simpledbf python module, but Python in City Engine gives an error on execution,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Traceback (most recent call last):
  File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
  File "testdbf.py", line 9, in &amp;lt;module&amp;gt;
    import simpledbf
ImportError: No module named simpledbf&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there something I have to do to include external python modules in order to work with City Engine Python?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 09:05:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/reading-a-dbf-file-and-extracting-data-with-python/m-p/1037935#M10138</guid>
      <dc:creator>CL11</dc:creator>
      <dc:date>2021-03-18T09:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a DBF file and extracting data with Python in City Engine 2019</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/reading-a-dbf-file-and-extracting-data-with-python/m-p/1037983#M10140</link>
      <description>&lt;P&gt;My Esri/Python experience doesn't extend into CityEngine much, as I only used it for a single project a couple years ago. &lt;A href="https://doc.arcgis.com/en/cityengine/latest/python/python-special-scripts.htm#ESRI_SECTION1_CFFB536DD78E41D98F13EDEAD8FBF2DA" target="_self"&gt;Looking at the docs&lt;/A&gt;, however, it does look like you could get an external module brought in by using the &lt;STRONG&gt;scripting.py&lt;/STRONG&gt; file.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Typical use cases include adding your scripting directory to the system path, or loading your custom modules to the scripting environment.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A href="https://doc.arcgis.com/en/cityengine/2019.0/tutorials/tutorial-10-python-scripting.htm" target="_self"&gt;Tutorial 10&lt;/A&gt; goes a step further and gives a concrete example:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;To extend scripting.py, complete the following steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a new file scripting.py in your CityEngine workspace using the file browser of your operating system.&lt;/LI&gt;&lt;LI&gt;Add the following lines to automatically map your helper script at startup:&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;import sys&lt;BR /&gt;&lt;BR /&gt;sys.path.append({PATH_TO_YOUR_SCRIPTS_DIRECTORY})&lt;BR /&gt;// e.g. sys.path.append("C:\user\CityEngine\MyProject\scripts")&lt;BR /&gt;import myHelpers&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I would presume that the path being appended could as easily point to a module somewhere.&lt;/P&gt;&lt;P&gt;Side note: have you checked out the python module &lt;A href="https://github.com/Toblerity/Fiona" target="_self"&gt;Fiona&lt;/A&gt;? It's fantastic for working with SHPs and DBFs.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 12:21:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/reading-a-dbf-file-and-extracting-data-with-python/m-p/1037983#M10140</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-03-18T12:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a DBF file and extracting data with Python in City Engine 2019</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/reading-a-dbf-file-and-extracting-data-with-python/m-p/1038439#M10143</link>
      <description>&lt;P&gt;Thanks for the suggestion. I tried making a scripting.py with the import sys and sys.path.append and import of simpledbf&amp;nbsp; and placed that in the project root folder, then re-started city Engine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, it still gives the same error on execution for simpledbf.&amp;nbsp; I also tried just doing the myHelper.py example and it also did not work (perhaps this solution is for the Python console and not for scripts.)&lt;/P&gt;&lt;P&gt;I also tried moving simpledbf into my project's scripts directory. No luck.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The final solution:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;In my python script itself,&lt;/P&gt;&lt;P&gt;I added the lines -&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import sys

sys.path.append (with the path being my project scripts directory)

from simpledbf import Dbf5&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then I put simpledbf.py in that scripts directory.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This did work - I was able to read DBF's and query values.&lt;/P&gt;&lt;P&gt;As far as Fiona - I would like to use it, unfortunately, City Engine's python is using Jython 2.7 while Fiona requires CPython 3.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 05:02:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/reading-a-dbf-file-and-extracting-data-with-python/m-p/1038439#M10143</guid>
      <dc:creator>CL11</dc:creator>
      <dc:date>2021-03-19T05:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a DBF file and extracting data with Python in City Engine 2019</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/reading-a-dbf-file-and-extracting-data-with-python/m-p/1038549#M10144</link>
      <description>&lt;P&gt;Great detective work! I'm sure the next person to have this issue will be glad you took the time to post the solution.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 12:04:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/reading-a-dbf-file-and-extracting-data-with-python/m-p/1038549#M10144</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-03-19T12:04:22Z</dc:date>
    </item>
  </channel>
</rss>

