Select Streets or Sidewalks based on width

07-05-2022 02:22 AM
New Contributor II

Hi all, 

I'm hoping this one is relatively straightforward - I've looked through documentation and articles but couldn't quite find an answer. 

I'm looking to automatically select streets or sidewalks based on their widths (actually, within a certain range of widths), so I can apply certain attributes using the complete streets rules. 

This seems like a job for a python script?

Wondering if any has any suggestions for this.


0 Kudos
4 Replies
New Contributor III

Hi Matt,

hereunder a python script to select graph segments by streetWidth attribute, just replace the min and max values (without quotes) in the last line by your desired range values:



Created on 06 Jul 2022
@author: PFontes
from scripting import *

# get a CityEngine instance
ce = CE()

def selectByAttribute(attr, minValue, maxValue):
    objects = ce.getObjectsFrom(ce.scene, ce.isGraphSegment)
    selection = []
    for item in objects:
        attribute = ce.getAttribute(item, attr)
        if attribute >=  minValue and attribute <= maxValue:

if __name__ == '__main__':
    selectByAttribute("/ce/street/streetWidth", "(minimum value inclusive)", "(maximum value inclusive)")




Hope this is what you're looking for.

New Contributor II

@plfontes - thank you for the quick response on this. This does look like what I'm looking for, however it isn't currently working so I think I'm missing a step somewhere along the way..

I've created a new python module (with your code), in the same cityengine project as the scene file - for testing's sake I've tried very large values (0 to 1500) and smaller ones (0 to 15). 

When I run the script (Python > Run Script?), no streets are selected. In the screenshot below I've manually selected one of the streets with a width of 10, so this should in theory be selected by the script.



Can you see any steps I've missed here?



0 Kudos
New Contributor III

Yes, my bad.

just include a "/" at the beginning of the attribute name in the last line to look like this "/ce/street/streetWidth"

Should work now.


0 Kudos
New Contributor II

Works like a charm. Thank you!