City Engine color

6132
19
Jump to solution
03-08-2013 12:38 AM
chiaramallegni
New Contributor
Hi,
I need to color with different color each building from one single group using the same rule for each building. I would classified with different color each building following an attribute (value field). How to do? What is the right CGA rule?
Thank's
chiara
0 Kudos
1 Solution

Accepted Solutions
MatthiasBuehler1
Frequent Contributor II
This should work :
 // Attributes attr Q_GRONDA = "" # string ! attr STANZA = ""   // Functions  red           = "#ffaaaa" green        = "#aaffaa" blue          = "#aaaaff" turquoise   = "#ooebeb" white        = "#ffffff" yellow       = "#ffff73" grey         = "#9c9c9c"   // Start !  @StartRule Lot -->     extrude (float (Q_GRONDA))     Colorizer  Colorizer-->     case STANZA == "4_1" :         color(red)         Continue      case STANZA == "7_2" :         color(yellow)         Continue      case STANZA == "1_3" :         color(blue)         Continue      case STANZA == "4_3" :         color(green)         Continue      else :         color(white)         Continue   Continue -->     comp(f) { side : Facade. | top : roofHip(30,0.5) Roof. }  

View solution in original post

0 Kudos
19 Replies
MatthiasBuehler1
Frequent Contributor II
Hi !

What's the attr type ? float ? string ?


let me know .. Matt

ps. this tutorial may help you with the very basics :
http://forums.arcgis.com/threads/53008-GIS-Data-Mini-Tutorial-Building-Height-and-Floor-Splits
0 Kudos
chiaramallegni
New Contributor
The attr is string....Thank's a lot!

Chiara
0 Kudos
MatthiasBuehler1
Frequent Contributor II
I'd try something like this for starters ..

Ok ?

r,g,b = red, green, blue



attr myAttr = "" # point source to object attr ( gis data )


colorFunction(colorChannel) = 
    case myAttr == "string_1" :
        case colorChannel == "r" : .3
        case colorChannel == "g" : .4
        else : 0.5 # b
     case myAttr == "string_2" :
        case colorChannel == "r" : .2
        case colorChannel == "g" : .7
        else : 1  #b
    else :
     ..

Lot -->
    color (colorFunction("r"),colorFunction("g"),colorFunction("b") )
0 Kudos
chiaramallegni
New Contributor
Dear Matthias Buehler,
frist of all thank's for your time.
unfortunatly the code dosn't work, my GIS attr is "STANZA" but there are some errors:
1) colorFunction(colorChannel) =  (mismathched Token)
2) case (mismathched Token).

I I have recently started to work with City Engine and I do not Know many code an low of code.

All the best.


Chiara
0 Kudos
MatthiasBuehler1
Frequent Contributor II
hi ..

just for information, the above was just an example, without correct code.. that code WILL produce errors.

can you post your code ?

m.
0 Kudos
chiaramallegni
New Contributor
I have two different way:

1:

attr Q_GRONDA =0
lot --> extrude (Q_GRONDA)

attr myAttr = "STANZA"

//colorFunction
colorFunction(colorChannel) =
case myAttr == "4_2" :
case colorChannel == "r" : .3
case colorChannel == "g" : .4
else : 0.5 # b
case myAttr == "7_2" :
case colorChannel == "r" : .2
case colorChannel == "g" : .7
else : 1 #b

Lot -->
color (colorFunction("r"),colorFunction("g"),colorFunction("b") )

2:

attr Q_GRONDA =0
lot --> extrude (Q_GRONDA)

# color declarations
red = "#ffaaaa"
green = "#aaffaa"
blue = "#aaaaff"
turquoise = "#ooebeb"
white = "#ffffff"
yellow = "#ffff73"
grey = "#9c9c9c"

attr STANZA = ""

// Functions
attr (STANZA) -->
case STANZA == "4_1" : red
case STANZA == "7_2" : yellow
case STANZA == "1_3" : blue
case STANZA == "4_3" : green
else : white

Where is my error? (attr Q_GRONDA =0 lot --> extrude (Q_GRONDA) is ok! )
0 Kudos
MatthiasBuehler1
Frequent Contributor II
This should work :
 // Attributes attr Q_GRONDA = "" # string ! attr STANZA = ""   // Functions  red           = "#ffaaaa" green        = "#aaffaa" blue          = "#aaaaff" turquoise   = "#ooebeb" white        = "#ffffff" yellow       = "#ffff73" grey         = "#9c9c9c"   // Start !  @StartRule Lot -->     extrude (float (Q_GRONDA))     Colorizer  Colorizer-->     case STANZA == "4_1" :         color(red)         Continue      case STANZA == "7_2" :         color(yellow)         Continue      case STANZA == "1_3" :         color(blue)         Continue      case STANZA == "4_3" :         color(green)         Continue      else :         color(white)         Continue   Continue -->     comp(f) { side : Facade. | top : roofHip(30,0.5) Roof. }  
0 Kudos
chiaramallegni
New Contributor
Dear Matthias,
Thank's, the code now work. I've modified someting, frist of all attr Q_GRONDA is not string but value (is the height of my building). Now all work but the color of building work in ralation with extrud, I praefer be indipendent each other, but also like this is ok.
I do a master thesis with City Engine, so, can I disturb you other time? 
Two other things: you wrote in the previaous code :"top : roofHip(30,0.5) Roof", when I applicate the roof of buildings became from flat to sloping, roofHip(30,0.5) is the code for sloping roof? Wher I can found library with different ty pes of shape like that?
It's possible applicate transparency?


This is my  modyfyed code:

// Attributes
attr Q_GRONDA = 1
attr STANZA = ""

// Functions

red           = "#ffaaaa"
green        = "#aaffaa"
blue          = "#aaaaff"
turquoise   = "#ooebeb"
white        = "#ffffff"
yellow       = "#ffff73"
grey         = "#9c9c9c"

// Start !

@StartRule


lot --> extrude (Q_GRONDA)
Colorizer
Colorizer -->
    case STANZA == "8_1" :
        color(red)
    case STANZA == "7_1" :
        color(yellow)
        comp (f){ side : facade.}
    case STANZA == "1_3" :
        color(blue)
    case STANZA == "magazzino_2" :
        color(green)
        comp (f){ side : facade.}
    else :
        color(turquoise)
        comp (f){ side : facade.}

all the best.

chiara
0 Kudos
MatthiasBuehler1
Frequent Contributor II
Ciao chiara,

Sure, post more questions here ..

:)


You find other standard roof types and all other CGA operations in the CGA code reference. Go to the Help Menu (F1).

You can make materials transparent by writing :

set (material.opacity, 0.3)
0 Kudos