How to correctly import a file, which is defined via the attributes?

04-08-2016 05:33 AM
New Contributor

Hello everybody

First of all: I'm a new user of CityEngine, so maybe this is a very basic question.. but I wasn't albe to find a good solution so far, that's the reason for my post here ;)

I would like to create buildings with ground- and upperfloors (so that I can combine the groundfloors randomly with the upperfloors). For this, I created the CGA-Files with the help of the Facade Wizard. These rule files provide the upperfloor rules only, the groundfloors are definied in different rule files.

At the moment, I wrote the following CGA-Code to divide the buildings into a ground- and upperfloor. It would be now possible to import a specific rule file for the groundfloors (by using the command import i : "name.cga"). What I would like to do is, that I can change the rule files for the groundfloors via the attributes (so I don't need to go into every rule file and change the name manually). Is that even possible?


attr Building_Height = 25

attr GroundFloorHeight = 5

attr UpperFloorHeight = 3

attr UpperFloorRule = "name.cga"

import i : UpperFloorRule #this one does not work, it should just give you an idea what I want to do: importing the cga-file, which was entered in the attribute part (in this case: "name.cga"). It would work with "import i : name.cga" though.


    extrude (world.y, Building_Height) Building

Building -->

    split(y){GroundFloorHeight: GF | {~UpperFloorHeight: UF}* }


    extrude (world.y, GroundFloorHeight)

    comp(f) {side: i.Facade}


    extrude (world.y, UpperFloorHeight)

    comp(f) {side: Facade}

=============End of Code=============

Thanks very much for your inputs. Have a nice weekend.


EDIT: this is not the complete code (just because of "End of Code"), the Facade rule is defined in the same file (but not displayed here)

Tags (3)
0 Kudos
4 Replies
Regular Contributor

Unfortunately that doesn't work. Import paths are static. You could however use Python to write a specific CGA file for each shape (using its attributes, for example), save and assign it. Of course that leaves you with tons of CGA files.

New Contributor

Thank you very much.

So there is no way without Python to combine two cga-files randomly together? Because I have definied the upper floors and the ground floors in different cga-files. My idea was now to combine these two cga files either by defining them manually.. or it would also be possible to combine them randomly.

Maybe I should create (extrude) the groundfloors first, add the cga file and create then the upperfloors on the top and add a different cga file then, would that be a work around?

0 Kudos
New Contributor

Oh sorry.. this just popped into my mind:

Maybe there would be a way to import a random file? Because there is a function fileRandom("name_nr*.cga").

0 Kudos
Regular Contributor

I never got anything dynamic to work with importing rules within CGA. If you want some randomness you could try something like this:

attr RN = rand(0,1)

Lot -->
  case RN > 0 && RN <= 0.1: Rule1
  case RN >0.1 && RN <= 0.2: Rule2
  case RN >0.2 && RN <= 0.3: Rule3
  else: Rule999

You either import all rules into the main one and randomly access one of them, or you combine all secondary rules into one, and put that case instruction in the secondary rule... or you mix both. I had some hangups when importing a "large" (~20) amount of complex rules, so maybe the second approach would be safer. Also since the rand() function is determined by the shape seed (which doesn't change until told to) you have to update it (⌂+, or ctrl+shift+g) to see changes.