<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python code: Selecting all objects with one attribute in ArcGIS CityEngine Questions</title>
    <link>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1285528#M10980</link>
    <description>&lt;P&gt;Remove /ce/geometry/ and it should work&lt;/P&gt;&lt;LI-CODE lang="c"&gt;selectByAttribute("amenity", "school")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 May 2023 06:54:07 GMT</pubDate>
    <dc:creator>MJF</dc:creator>
    <dc:date>2023-05-04T06:54:07Z</dc:date>
    <item>
      <title>Python code: Selecting all objects with one attribute</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1285503#M10979</link>
      <description>&lt;P&gt;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?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;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")&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 04 May 2023 03:18:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1285503#M10979</guid>
      <dc:creator>AlexWierzbicki</dc:creator>
      <dc:date>2023-05-04T03:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python code: Selecting all objects with one attribute</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1285528#M10980</link>
      <description>&lt;P&gt;Remove /ce/geometry/ and it should work&lt;/P&gt;&lt;LI-CODE lang="c"&gt;selectByAttribute("amenity", "school")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 06:54:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1285528#M10980</guid>
      <dc:creator>MJF</dc:creator>
      <dc:date>2023-05-04T06:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Python code: Selecting all objects with one attribute</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1285532#M10981</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/662423"&gt;@AlexWierzbicki&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;For a python newbie you got already quite far &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;For object attributes you don't need any prefix just write &lt;EM&gt;selectByAttribute("amenity", "school")&lt;/EM&gt; and your script should work.&lt;/P&gt;&lt;P&gt;I suggest two other small improvements to your script:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Add &lt;EM&gt;@noUIupdate&lt;/EM&gt; before your function. This makes sure the UI will be refreshed only after the function is run through. Depending on the size of the scene and what your function does this can speed up the run significantly&lt;/LI&gt;&lt;LI&gt;In your case you don't need to query all objects from the scene, you can limit it to shapes only if you &lt;EM&gt;write objects = ce.getObjectsFrom(ce.scene, ce.isShape)&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Cheers,&lt;BR /&gt;Jonas&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 07:07:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1285532#M10981</guid>
      <dc:creator>JonasObertuefer</dc:creator>
      <dc:date>2023-05-04T07:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: Python code: Selecting all objects with one attribute</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1290928#M11004</link>
      <description>&lt;P&gt;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&amp;nbsp;@noUIupdate&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlexWierzbicki_0-1684463010311.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71130i52F0270AEBD5CF80/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlexWierzbicki_0-1684463010311.png" alt="AlexWierzbicki_0-1684463010311.png" /&gt;&lt;/span&gt;&lt;BR /&gt;Below is the code. Any other advice?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 02:24:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1290928#M11004</guid>
      <dc:creator>AlexWierzbicki</dc:creator>
      <dc:date>2023-05-19T02:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Python code: Selecting all objects with one attribute</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1290999#M11005</link>
      <description>&lt;P&gt;hi again,&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;@noUIupdate needs to be directly above the function you want to trigger no UI updates&lt;/LI&gt;&lt;LI&gt;change the filter in your getObjectsFrom() from ce.isGraphSegment to ce.isShape. Amenity is isuallay a object attribute assigned to shapes.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I tested the the code below, and it works for me:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# 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")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 12:34:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/python-code-selecting-all-objects-with-one/m-p/1290999#M11005</guid>
      <dc:creator>JonasObertuefer</dc:creator>
      <dc:date>2023-05-19T12:34:47Z</dc:date>
    </item>
  </channel>
</rss>

