<?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 Working with paths in cityengine python script execution - Tip in ArcGIS CityEngine Questions</title>
    <link>https://community.esri.com/t5/arcgis-cityengine-questions/working-with-paths-in-cityengine-python-script/m-p/13941#M158</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This may help others if you come across odd behaviour.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm running on win7.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I was having a number of issues breaking a path up in script execution, the confusing thing is that it works fine in the console, so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
#in CE python console
import os.path
myPath="c:\\assets\\buildings\\downtown\\building_A.obj"
assetName=os.path.split(myPath)[1]
assetName=os.path.splitext(assetName)[0]

#or if your pythonic-ally one line inclined:

assetName=os.path.splitext(os.path.split(myPath)[1])[0]

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Doing the same in script execution was not working and I couldn't figure out why i wasn't getting the same result's.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SO make sure you switch your backslashes to forward slashs, unix style, for paths that are handled in scripts if you want to use os.path operations:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
myPath="c:\\assets\\buildings\\downtown\\building_A.obj"
myPath=myPath.replace("\\","/")
assetName=os.path.splitext(os.path.split(myPath)[1])[0]

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Magic now I get the results I'm expecting.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Jul 2012 22:42:12 GMT</pubDate>
    <dc:creator>RobertHexter</dc:creator>
    <dc:date>2012-07-25T22:42:12Z</dc:date>
    <item>
      <title>Working with paths in cityengine python script execution - Tip</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/working-with-paths-in-cityengine-python-script/m-p/13941#M158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This may help others if you come across odd behaviour.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm running on win7.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I was having a number of issues breaking a path up in script execution, the confusing thing is that it works fine in the console, so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
#in CE python console
import os.path
myPath="c:\\assets\\buildings\\downtown\\building_A.obj"
assetName=os.path.split(myPath)[1]
assetName=os.path.splitext(assetName)[0]

#or if your pythonic-ally one line inclined:

assetName=os.path.splitext(os.path.split(myPath)[1])[0]

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Doing the same in script execution was not working and I couldn't figure out why i wasn't getting the same result's.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SO make sure you switch your backslashes to forward slashs, unix style, for paths that are handled in scripts if you want to use os.path operations:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
myPath="c:\\assets\\buildings\\downtown\\building_A.obj"
myPath=myPath.replace("\\","/")
assetName=os.path.splitext(os.path.split(myPath)[1])[0]

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Magic now I get the results I'm expecting.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 22:42:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/working-with-paths-in-cityengine-python-script/m-p/13941#M158</guid>
      <dc:creator>RobertHexter</dc:creator>
      <dc:date>2012-07-25T22:42:12Z</dc:date>
    </item>
  </channel>
</rss>

