Hoping that someone can help me out. I am a python newbie and I am trying to create a script that will select all objects that have the Object Attribute "amenity" equal to "school". Could some please help me identify what is wrong with the below code?
from scripting import *
# get a CityEngine instance
ce = CE()
def selectByAttribute(attr, value):
objects = ce.getObjectsFrom(ce.scene)
selection = []
for item in objects:
attribute = ce.getAttribute(item, attr)
if attribute == value:
selection.append(item)
ce.setSelection(selection)
if __name__ == '__main__':
selectByAttribute("/ce/geometry/amenity", "school")
Solved! Go to Solution.
hi again,
I tested the the code below, and it works for me:
# get a CityEngine instance
ce = CE()
@noUIupdate
def selectByAttribute(attr, value):
objects = ce.getObjectsFrom(ce.scene, ce.isShape)
selection = []
for item in objects:
attribute = ce.getAttribute(item, attr)
if attribute == value:
selection.append(item)
ce.setSelection(selection)
if __name__ == '__main__':
selectByAttribute("amenity", "school")
Hi @AlexWierzbicki,
For a python newbie you got already quite far 😉
For object attributes you don't need any prefix just write selectByAttribute("amenity", "school") and your script should work.
I suggest two other small improvements to your script:
Cheers,
Jonas
I've made the suggested changes but unfortunately it is still not working, receiving either the following error or nothing at all happening, depending on where I put the @noUIupdate
Below is the code. Any other advice?
from scripting import *
@noUIupdate
# get a CityEngine instance
ce = CE()
def selectByAttribute(attr, value):
objects = ce.getObjectsFrom(ce.scene, ce.isGraphSegment)
selection = []
for item in objects:
attribute = ce.getAttribute(item, attr)
if attribute == value:
selection.append(item)
ce.setSelection(selection)
if __name__ == '__main__':
selectByAttribute("amenity", "school")
hi again,
I tested the the code below, and it works for me:
# get a CityEngine instance
ce = CE()
@noUIupdate
def selectByAttribute(attr, value):
objects = ce.getObjectsFrom(ce.scene, ce.isShape)
selection = []
for item in objects:
attribute = ce.getAttribute(item, attr)
if attribute == value:
selection.append(item)
ce.setSelection(selection)
if __name__ == '__main__':
selectByAttribute("amenity", "school")