AnsweredAssumed Answered

Using Python to create an object attribute from a rule attribute

Question asked by BCBD_GIS on Jul 27, 2017
Latest reply on May 2, 2018 by CLau-esristaff

I am trying to write a python script that will create a new object attribute containing the parcel area for any number of parcels I’ve selected in the scene. I know I need to use Export (Reporting) python script to fetch the value of a rule attribute.


Proposed method:

  1. Select the desired parcels in the scene
  2. Run a python script that assigns the CGA rule “calculateParcelArea.cga” to each of the parcels, generates the models using “calculateParcelArea.cga”, and reports the area in the Parcel_Area row, under the sum column.
  3. The python script then fetches the reports for each of the parcels, creates a new object attribute named ‘parcelArea’ for each parcel, and assigns the reported value.


So far I’ve written a regular python (Module: Main) script that assigns the “calculateParcelArea.cga” to the selected parcels, generates the models with areas saved to rule attribute ‘parcelArea_Calc’, and reports the value.


I’m having difficulty with the Export (Reporting) python module. Can someone help me make sense of this? How do I bring the existing script into the Export (Reporting) python module to complete the task?  



Python script and CGA rule below:



Created on 2017-07-26

@author: bcbd


from scripting import *


# get a CityEngine instance

ce = CE()


def parcelArea():      

    shapes = ce.getObjectsFrom(ce.selection, ce.isShape)

    for shape in shapes:

        ce.setRuleFile(ce.selection(), 'calculateParcelArea.cga')

  # assign CGA rule calcParcelArea

        ce.setStartRule(ce.selection(), 'Lot')



if __name__ == '__main__':





 * File:    calculateParcelArea.cga



version “2017.0”

attr parcelArea_Calc = geometry.area


Lot -->

      report("Parcel_Area", parcelArea_Calc)

print("Parcel_Area: " + parcelArea_Calc)