How can I change the color of roof?

258
1
02-06-2019 01:12 PM
FanjieKong
New Contributor II

Now I have a rule file for buildings. I want to use python scripts to change the color of roof. How can I achieve this.

I know we can use statement like

"selectedSegments = ce.getObjectsFrom(ce.selection, ce.isGraphSegment)
for segment in selectedSegments:
oldWidth = ce.getAttribute(segment, "/ce/street/streetWidth")
newWidth = oldWidth+increment
ce.setAttribute(segment, "/ce/street/streetWidth", newWidth)"

But please tell me where can I find the location of 'color'?

0 Kudos
1 Reply
CherylLau
Esri Regular Contributor

The above python code changes the width of a street segment (graph segment) by setting the built-in street parameter streetWidth.

To set the color of the roof in your building rule, you'll probably want to work with shapes, not graph segments.  In your scene, you could apply your building rule to some shapes.  The cga rule could have an attribute for roof color.

@Color
attr roof_color = "#ffffff"‍

In the cga code, use the *color()* operation to set the color of the roof based on the attribute value.

color(roof_color)‍

color Operation 

To use python to set the value of the rule attribute for the roof color, the python script should create an object attribute with the same name as the rule attribute (roof_color) and then assign the building rule file to the shape.  Once the rule is assigned, rule attributes will be automatically connected to object attributes with the same name.

ce.setAttribute(shape, 'roof_color', '#ff0000')
ce.setRuleFile(shape, 'building_rule.cga')