Apply colors based on attribute values

377
2
09-12-2018 12:58 AM
ChristophRuggli
New Contributor II

Dear all

I try to wirte a cga rule for underground utilitys, especially pipes. I give the objects following information:

Height: VPKOTE

Radius: Radius 

Form: Model of Pipeline

Nutzungsart: Type of use (sewage, fresh water etc) which should be displayed with different colors

I don't understand why CE won't take the values out off the attribute table and colorize it...

 

This is my rule:


version "2018.0"


// Attributes
attr VPKOTE = 0
attr Radius = 0
attr Form = ("Pipe")
attr Nutzungsart = 0

// Functions
red = "#ffaaaa"
green = "#00ae00"
blue = "#aaaaff"
turquoise = "#ooebeb"
white = "#ffffff"
yellow = "#ffff73"
grey = "#9c9c9c"

// Start !

@StartRule

LOT -->
extrude(world.y, VPKOTE)
extrude(Radius)
color(Nutzungsart)


color -->
case Nutzungsart == 1 : color(red)
case Nutzungsart == 2 : color(green)
else : color (yellow)

PipeAsset =
case Form == "Pipe" :
"assets/pipe.obj"
else: "assets/pipe.obj"

I appreciate any help and tipps!

Thanks in advance

Christoph

0 Kudos
2 Replies
ThomasFuchs
Esri Regular Contributor

Hello Chistoph

In your code you used "color" as a rule name. Additionally it is also a CGA operation
http://desktopdev.arcgis.com/en/cityengine/latest/cga/cga-color.htm

I advise you to rename the rule to "setColor" and do not hand over the attribute "Nutzungsart". This should do the trick:

version "2018.1"

// Attributes
attr VPKOTE = 0
attr Radius = 0
attr Form = ("Pipe")
attr Nutzungsart = 0


// Functions
red = "#ffaaaa"
green = "#00ae00"
blue = "#aaaaff"
turquoise = "#ooebeb"
white = "#ffffff"
yellow = "#ffff73"
grey = "#9c9c9c"



// Start !
@StartRule
LOT -->
extrude(world.y, VPKOTE)
extrude(Radius)
setColor

setColor -->
case Nutzungsart == 1 : color(red)
case Nutzungsart == 2 : color(green)
else : color (yellow)

PipeAsset =
case Form == "Pipe" :
     "assets/pipe.obj"
else: "assets/pipe.obj"

mfG
Thomas F

ChristophRuggli
New Contributor II

Hi Thomas

This is perfect! 

Thank you very much

Christoph

0 Kudos