Importing Rules From Other CGA Files

Rules from an existing rule file can be imported by a rule file through "import". Importing a rule file makes all rules,attributes and functions of the imported rule file available under the given prefix.

Example

Combining two facades with a structure

# -- facade1.cga

actualFloorHeight = scope.sy/rint(scope.sy/4)
actualTileWidth   = scope.sx/rint(scope.sx/4)
    
Facade -->
    setupUV(0, 8*actualTileWidth, 8*actualFloorHeight)
    set(material.colormap, "f1.tif")
    bakeUV(0)
# -- facade2.cga

actualFloorHeight = scope.sy/rint(scope.sy/6)
actualTileWidth   = scope.sx/rint(scope.sx/4)
    
Facade -->
    setupUV(0, 8*actualTileWidth, 8*actualFloorHeight)
    set(material.colormap, "f2.tif")
    bakeUV(0)
# -- structure.cga

// the attribute height will be overridden by the
// attribute height from "main.cga" if this rule
// file is included. Thus if this rule file is
// used standalone, the buildings will be of height
// 100, if this rule file is included by "main.cga",
// the buildings will be of height 200.
attr height = 100

Lot-->extrude(height) Mass

Mass-->comp(f){ side: Facade | top: Roof }
# -- main.cga

// define an attribute "height", potentially
// overriding the same attribute in imported
// rule files.

attr height = 200

// import facades
import f1 : "facade1.cga"
import f2 : "facade2.cga"

// import structure
import st : "structure.cga"

Lot-->
  // reference rule "Lot" in structure.cga
    st.Lot

// define rule "Facade" for structure.cga
st.Facade-->
  // reference rule "Facade" in facade1.cga
    50%  : f1.Facade  
  // reference rule "Facade" in facade2.cga
    else : f2.Facade

CGA Reference

Copyright ©2008-2016 Esri R&D Center Zurich. All rights reserved.