CityEngine assign color from attribute

2839
2
Jump to solution
12-23-2013 11:53 AM
HeathAnderson
Occasional Contributor II
I am trying to assign a color based on an attribute from my shapefile.  The attribute is "diskcolor" and is a string.  Here is my code

//Attribute
attr diskcolor = ""

//Functions
Red = "FF0000"
Blue = "0000FF"
Yellow = "FFFF00"
White = "FFFFFF"

// Start !
@StartRule
disk = fileRandom("assets/disk.obj")

Lotdisk--> r(-90,0,0) s(0,1,0) center(xz) i(disk) disk.
Colorizer
Colorizer-->
case diskcolor == "1" :
color(Red)
case diskcolor == "2" :
color(Blue)
case diskcolor == "5" :
color(Yellow)
else :
color(White)

Can someone please help. I am not sure what is wrong, but i believe that the code is not getting the attribute from the shapefile even though I have set the source as "Layer attribute"

Thoughts?
[ATTACH=CONFIG]30082[/ATTACH]
0 Kudos
1 Solution

Accepted Solutions
HeathAnderson
Occasional Contributor II
After some additional research and trail and error I was able to get the code to work.  I had to change some things around then remove and add the shapefile but it works.

//Attribute
attr dcolor = "" # string !

//Functions
Red =   "#FF0000"
Blue =   "#0000FF"
Yellow =          "#FFFF00"
White =          "#FFFFFF"

// Start !
@StartRule
disk = fileRandom("assets/disk.obj")

Lotdisk--> r(-90,0,0) s(0,1,0) center(xz) disk.
Colorizer
Colorizer-->
case dcolor == "1" :
color(Red)
i(disk)
case dcolor == "7" :
color(White)
i(disk)
case dcolor == "5" :
color(Blue)
i(disk)
else :
color(Yellow)
i(disk)

View solution in original post

0 Kudos
2 Replies
HeathAnderson
Occasional Contributor II
After some additional research and trail and error I was able to get the code to work.  I had to change some things around then remove and add the shapefile but it works.

//Attribute
attr dcolor = "" # string !

//Functions
Red =   "#FF0000"
Blue =   "#0000FF"
Yellow =          "#FFFF00"
White =          "#FFFFFF"

// Start !
@StartRule
disk = fileRandom("assets/disk.obj")

Lotdisk--> r(-90,0,0) s(0,1,0) center(xz) disk.
Colorizer
Colorizer-->
case dcolor == "1" :
color(Red)
i(disk)
case dcolor == "7" :
color(White)
i(disk)
case dcolor == "5" :
color(Blue)
i(disk)
else :
color(Yellow)
i(disk)
0 Kudos
MatthiasBuehler1
Frequent Contributor II
Hi !

Glad you found a solution !

matt
0 Kudos