Problem with Conditional Rule writing

2301
3
02-06-2012 01:49 AM
DaveCapstick
New Contributor
Hi,
i am new to City Engine, so this might be a simple problem.
I have an ESRI Shape file for building footprints with average building height and classified roof types (simple classification of 'flat', 'hipped', 'gable'.  I have imported this into CE ok.  I am now in the process of writing a rule file to extrude the footprint up to the average building height and create a rooftype that fits in with the classified roof types in the Shape file. I have set an attribute in the rule file for building height as = 6, as a default and have also used the Attribution connection editor to connect the attribute in my Shape file to the layer i am working on. This effectively over rides the default height of 6 that i put in my rule file.  I have also done this for the roofType attribute.  Now, in my rule file i have this as the script, with height and roofType being the attributes in my Shape file:-


attr height = 6    - Default height
attr roofType = "Hipped"  - Default roofType

Lot --> extrude(height) Mass


Mass (roofType)-->
case roofType = "Hipped" : roofHip(20) Final
case roofType = "Pyramid" : roofPyramid(20) Final
Else : NIL

I would like to generate a Hipped roof or a Pyramid roof dependent on the attribute from my original Shape file.  However, i keep getting a message that says 'Mismatched token (=)'. Does anyone have any suggestions as to where i am going wrong?

Regards

Dave
Tags (2)
0 Kudos
3 Replies
MatthiasBuehler1
Frequent Contributor
hi Dave !

great start you have there already !


2 issues :

1] a conditional statement resulting in TRUE or FALSE (a boolean value) must be written with '==', not '=' because you're comparing, not setting a value.
2] have a look at the comp() operation. in the current code you have, you build a roof on all sides of Mass, even on the vertical ones. Thus, you need to select just the top one to create a roof on that one.

additional reading / viewing :
http://forums.arcgis.com/threads/44417-CGA-Understanding-the-concept-of-the-scope

this will make things clearer.


keep us posted with the progress !

cheers !

Matt
0 Kudos
DaveCapstick
New Contributor
Hi Matt,
thanks for responding to my post. Ok, i get the fact that i have to break the extruded shape up into its constituent faces using the comp operation and i can then apply more rules to each face. I've seen a few examples where that is explained.  I still seem to be having a few problems with the conditional rule i have written though. At the moment my rule file looks like this:-

attr height = 6
attr roofType = "Hipped"

Lot -->
extrude(height) Mass
Mass --> comp(f) {
  top: roofTop |
  all : bldgRest
  }


roofTop (roofType) -->
  case roofType == "Hipped" : roofHip(20) HippedRoof 
  case roofType == "Gable" : roofGable(20) GableRoof
  case roofType == "Pyramid" : roofPyramid(20) PyramidRoof
  case roofType == "Flat" : roofShed(0) FlatRoof
  else : NIL     

This seems to be only partially successful. I end up with a building geometry that only consists of flat roofs and doesn't seem to take into account the conditional rule i have set up.  I've used the attribute connection editor to link the attributes in the original imported Shape file to the attributes in the rule file.  That seems to work ok for creating the extruded buildings in the first part of the code. But it doesn't seem to work for the roofType attribute and the conditional rule.  This attribute is a text attribute in the Shape file, it does exist and i have connected to it ok.

Thanks

Dave
0 Kudos
MatthiasBuehler1
Frequent Contributor
hi !

the value in the brackets is a 'bucket' for passing a value to an other rule.

E.g.

(open the Console Window !)

Rule -->
    PrinterRule ("heya !")

PrinterRule (input) -->
    print (input)





Important : ATTRIBUTE values do not need to be passed like this, in the brackets but can directly be used in code.

attr value = 5

Lot -->
     case value == 5 :
         print("yay !")
    else :
        print ("booo !")




Note : The following 2 Rules are 2 DIFFERENT rule.

Rule(XYZ) -->
Rule -->




So in your code, you should change :
roofTop (roofType) -->

to :
roofTop -->



ok ?
0 Kudos