hjd_uk

Importing Scripts

Discussion created by hjd_uk on Jun 6, 2013
Latest reply on Jun 12, 2013 by MBuehler-esristaff
Hi, I have a number of scripts in the Workspace "scripts" folder, using the sys.path.append() method I am oftem but seeminlgy randomly getting errors when trying to run scripts that import scripts in the same directory:

from scripting import *
# get a CityEngine instance
ce = CE()

sys.path.append( ce.toFSPath("scripts/") )
import myModule


Sometimes it works fine, but often I get an error and the scripts refuses to run:

File "<string>", line 1, in <module>
  File "<...>\CityEngine_TestProject01\scripts\<script>.py", line 17, in <module>
    sys.path.append(ce.toFSPath("scripts/"))
NameError: name 'sys' is not defined

... which is odd as "sys" ought to always be available and it periodically works and then doesnt work.

After reloading CityEngine and trying a script it appears that some scripts work and some dont but it always seems to be random as to which ones will succeed and which wont.

Outcomes