Workspaces and Leveraging the ESRI Library: Rule Files

Primitive Cubes rendered from rules in two imported CGA files

Primitive Cubes rendered from rules in two imported CGA files

 

As I’ve started to build individual test projects, my attention has turned to how I should organize all of my CityEngine projects, resources and workspaces.  Originally, I tried having projects on two drives to conserve space on my workstation’s C drive. I’ve got a ton of other apps that take up considerable space and resources.  I first tried having a separate workspace for each project, but I found that annoying since CE does a total restart when you change workspaces.  I have finally concluded that locating all my projects in a single workspace folder is what works for me.

There is another reason why this is a good idea.  When you set up your first project in a workspace, CE will copy in it’s 135 Mb resource library, ESRI.lib.  This contains hundreds of jpg/png textures and 3D object files in the “assets” folder and about a dozen rule files for buildings, roofs, streets, plants, etc. in the “rules” folder.

With the keyword IMPORT, you can access RULE files externally from this library or internally from within your project. NOTE: THIS APPROACH DOES NOT WORK FOR ASSETS LIKE JPG OR PNG; you will get an error message and you may crash CE. In the folder structure shown on the left, I have two projects, “MyProject” and “MyOtherProject” plus the “ESRI.lib” library in the same workspace.  Two CGA rule files, “rule” and “project rule” are within the MyProject rule folder; another CGA file, “library rule” is in the library’s “rules” folder.  Here is how we access rule files using “import”:

# Create three CGA files and locate them in your folder structure as follows:

/**
* File: rule.cga
* Created: 22 May 2018 21:24:34 GMT
* Author: Jeff Herzer | www.jeffcity.io
* Location: MyProject/rules
*/

version "2017.1"
# use alias "r1" and import using an absolute file path
import r1 : "/ESRI.lib/rules/libraryRule.cga"
# use alias "r2" and import using a relative file path
import r2 : "projectRule.cga"

# Draws a primitive cube and applies rule r1
Start --> 
primitiveCube(5,5,5)
r1.ColorIt

# Draws another primitive cube and applies rule r2
StartAnother -->
primitiveCube(5,5,5)
r2.ColorIt

# ########################

/**
* File: LibraryRule.cga
* Created: 22 May 2018 21:57:15 GMT
* Author: Jeff Herzer | www.jeffcity.io
* Location: MyProject/rules
*/

version "2017.1"
# This rule colors the cube Red
ColorIt -->
color("#ff0000")

# ########################

/**
* File: projectRule.cga
* Created: 22 May 2018 21:57:01 GMT
* Author: Jeff Herzer | www.jeffcity.io
* Location: ESRI.lib/rules
*/

version "2017.1"
# This rule colors the cube green
ColorIt -->
color("#00ff00")


Leave a Reply

Your email address will not be published. Required fields are marked *