CGA attributes

Attributes are a set of static global variables defined in the rule file. Each attribute is initialized to a specific value in the rule file. The attribute values can individually be changed on a per shape basis. This can be done in the Rules pane in the Inspector.

Note:

In contrast to functions, attributes are evaluated only once at the beginning of the generation process.

Example

attr height = 150
attr landuse = "residential"

Lot --> extrude(height) Envelope(landuse)

Here, two attributes are defined using the attr keyword: height which is of type float and landuse which is a string. The attributes are used in the Lot rule.

Attributes can also be conditional or stochastic:

attr landuse = 50% : "residential" 
               else : "industrial"

Here, there is a 50% chance landuse evaluates to "residential" and a 50% chance it evaluates to "industrial". For each shape the conditional/stochastic attributes are evaluated once and stay constant during the generation process.

In the same way, the rand() function can be used:

attr height = rand(30,50)

Lot --> extrude(height) Envelope

Envelope --> 
    case height < 40 : SmallBuilding
    else: LargeBuilding

For each shape which has the start rule Lot, height evaluates to a value between 30 and 50 units. This height is constant and can be used everywhere in the rule file.

Note:
  • See Mapping Parameters for details how to use different sources to control input of rule attributes.
  • The display of attributes in the Inspector can be controlled by CGA annotations.
  • Interactive handles can be used to edit attributes in the 3D view.

Change attributes in Inspector

The values of functions marked with attr can be set individually for each initial shape in the Inspector. For instance, the definition below yields an entry in the Rule Parameters section.

@Range(min=10, max=40)
attr height = 20

You can click and edit the value or use the slider to modify the value. See Attributes, sources, and connections for more information.

Note:

The display of attributes can be controlled by CGA annotations.

Multi assign

It is possible to manually assign a value to multiple initial shapes in a convenient way. The following is an example of assigning attributes to multiple shapes:

  1. Select two initial shapes that have a rule file assigned with the attributes height, roofColor and roofType.

  2. Change the height value to 40.

    Both selected shapes have their height value changed.

  3. Select one shape (or model) only, and change the height back to the rule default 20.
  4. Select both models.

    The value of height is displayed as a question mark ?, stating that the two selected models do not share the same value for this attribute.