Importing Scripts

06-06-2013 02:30 AM
New Contributor
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>
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.
Tags (3)
0 Kudos
2 Replies
New Contributor
😐 appears that one of the imported scripts wasnt importing "sys".

Fixed by adding "import sys" to the scripts ( the Python console does this automatically but the auto-generated *.py scripts do not, thet only import "scripting" )
0 Kudos
Frequent Contributor
glad you found a solution !

cheers !
0 Kudos