<?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: Searching a shape by inputting attribute values in a GUI window using Python. in ArcGIS CityEngine Questions</title>
    <link>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1537535#M11449</link>
    <description>&lt;P&gt;It seems I did something unnecessary without even thoroughly reading the manual I had checked before. I will carefully read the help section again. Thank you for pointing it out.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Sep 2024 20:34:32 GMT</pubDate>
    <dc:creator>desert</dc:creator>
    <dc:date>2024-09-11T20:34:32Z</dc:date>
    <item>
      <title>Searching a shape by inputting attribute values in a GUI window using Python.</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1531289#M11443</link>
      <description>&lt;P&gt;I received assistance here on how to find shapes using attribute values in a Python script.&lt;BR /&gt;Since it was inconvenient to directly input attribute values into the code each time, I tried entering them through the Python console, but it was impossible.&lt;BR /&gt;Then, I found a way to implement a GUI using Jython and tried it.&lt;/P&gt;&lt;P&gt;It's currently working well, including searches for Korean(2Bytes char) attributes. While it may not be the most elegant solution, I hope it helps others.&lt;BR /&gt;&lt;STRONG&gt;("Functional limitation - Search does not work when the attribute value is a number.")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;As a program designed to handle large datasets, CityEngine must include a core functionality to search for shapes based on their attributes.(Does this feature really exist, or am I missing something?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;div class="video-embed-center video-embed"&gt;&lt;iframe class="embedly-embed" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FPaZSH8_QPvU%3Ffeature%3Doembed&amp;amp;display_name=YouTube&amp;amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPaZSH8_QPvU&amp;amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPaZSH8_QPvU%2Fhqdefault.jpg&amp;amp;type=text%2Fhtml&amp;amp;schema=youtube" width="400" height="225" scrolling="no" title="Cityengine python Finding shapes by inputting attribute names and values" frameborder="0" allow="autoplay; fullscreen; encrypted-media; picture-in-picture;" allowfullscreen="true"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Last modified: 2024-08-29 19:00:00 KST
# Version: 1.4
# Requirement: Fix the issue where the input GUI window was not displaying correctly.

'''
@author: desert
'''
from scripting import *
from javax.swing import JFrame, JLabel, JTextField, JButton, JPanel
from java.awt import GridLayout, BorderLayout
from java.awt.event import ActionListener

# Get a CityEngine instance
ce = CE()

# selectByAttribute function: Select objects based on the attribute name and value
def selectByAttribute(attr, value):
    objects = ce.getObjectsFrom(ce.scene)
    selection = []
    for o in objects:
        attrvalue = ce.getAttribute(o, attr)
        if attrvalue == value:
            selection.append(o)
    
    ce.setSelection(selection)

# Class defining the GUI components
class InputFrame(JFrame, ActionListener):
    def __init__(self):
        self.createAndShowGUI()

    def createAndShowGUI(self):
        self.setTitle("Attribute Input")
        self.setSize(400, 150)
        self.setLayout(BorderLayout())

        # Add attribute name and value fields to the central panel
        panel = JPanel()
        panel.setLayout(GridLayout(2, 2, 10, 10))
        
        # Attribute name input field
        panel.add(JLabel("Attribute Name:"))
        self.attrField = JTextField(15)
        panel.add(self.attrField)
        # Attribute value input field
        panel.add(JLabel("Attribute Value:"))
        self.valueField = JTextField(15)
        panel.add(self.valueField)
        
        # Add the panel to the center
        self.add(panel, BorderLayout.CENTER)

        # Add Execute and Close buttons to the bottom
        buttonPanel = JPanel()
        buttonPanel.setLayout(GridLayout(1, 2, 10, 10))

        # Execute button
        self.button = JButton("Search", actionPerformed=self.actionPerformed)
        buttonPanel.add(self.button)
        
        # Close button
        self.closeButton = JButton("Cancel", actionPerformed=self.closeWindow)
        buttonPanel.add(self.closeButton)

        # Add the button panel to the bottom
        self.add(buttonPanel, BorderLayout.SOUTH)

        # Set the default close operation and make the GUI visible
        self.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
        self.setVisible(True)
    
    # Function triggered when the button is clicked
    def actionPerformed(self, event):
        attr = self.attrField.getText()
        value = self.valueField.getText()
        selectByAttribute(attr, value)
        print("Selected objects with attribute '{}' and value '{}'.".format(attr, value))
        self.dispose()
    
    # Function to close the window when the close button is clicked
    def closeWindow(self, event):
        self.dispose()

if __name__ == '__main__':
    # Launch the GUI window
    InputFrame()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Aug 2024 06:38:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1531289#M11443</guid>
      <dc:creator>desert</dc:creator>
      <dc:date>2024-08-31T06:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Searching a shape by inputting attribute values in a GUI window using Python.</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1533684#M11445</link>
      <description>&lt;P&gt;&lt;STRONG&gt;I've modified the code to allow searching for numerical attribute values&lt;/STRONG&gt; as well.&lt;/P&gt;&lt;P&gt;Please note that I'm a beginner in Python, so there might be some shortcomings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Last modified: 2024-08-31 16:00:00 KST
# Version: 1.7
# Requirement: Fix the issue float type attr value

'''
@author: desert
'''
from scripting import *
from javax.swing import JFrame, JLabel, JTextField, JButton, JPanel
from java.awt import GridLayout, BorderLayout
from java.awt.event import ActionListener

# Get a CityEngine instance
ce = CE()

# selectByAttribute function: Select objects based on the attribute name and value
def selectByAttribute(attr, value):
    objects = ce.getObjectsFrom(ce.scene)
    selection = []
    for o in objects:
        attrvalue = ce.getAttribute(o, attr)
        print(type(attrvalue))
        if isinstance(attrvalue,float) and attrvalue == float(value):
            selection.append(o)
        elif isinstance(attrvalue,str) and attrvalue == value: 
            selection.append(o)

    
    ce.setSelection(selection)

# Class defining the GUI components
class InputFrame(JFrame, ActionListener):
    def __init__(self):
        self.createAndShowGUI()

    def createAndShowGUI(self):
        self.setTitle("Attribute Input")
        self.setSize(400, 150)
        self.setLayout(BorderLayout())

        # Add attribute name and value fields to the central panel
        panel = JPanel()
        panel.setLayout(GridLayout(2, 2, 10, 10))
        
        # Attribute name input field
        panel.add(JLabel("Attribute Name:"))
        self.attrField = JTextField(15)
        panel.add(self.attrField)
        # Attribute value input field
        panel.add(JLabel("Attribute Value:"))
        self.valueField = JTextField(15)
        panel.add(self.valueField)
        
        # Add the panel to the center
        self.add(panel, BorderLayout.CENTER)

        # Add Execute and Close buttons to the bottom
        buttonPanel = JPanel()
        buttonPanel.setLayout(GridLayout(1, 2, 10, 10))

        # Execute button
        self.button = JButton("Search", actionPerformed=self.actionPerformed)
        buttonPanel.add(self.button)
        
        # Close button
        self.closeButton = JButton("Cancel", actionPerformed=self.closeWindow)
        buttonPanel.add(self.closeButton)

        # Add the button panel to the bottom
        self.add(buttonPanel, BorderLayout.SOUTH)

        # Set the default close operation and make the GUI visible
        self.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
        self.setVisible(True)
    
    # Function triggered when the button is clicked
    def actionPerformed(self, event):
        attr = self.attrField.getText()
        value = self.valueField.getText()
        selectByAttribute(attr, value)
        print("Selected objects with attribute '{}' and value '{}'.".format(attr, value))
        self.dispose()
    
    # Function to close the window when the close button is clicked
    def closeWindow(self, event):
        self.dispose()

if __name__ == '__main__':
    # Launch the GUI window
    InputFrame()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Aug 2024 07:27:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1533684#M11445</guid>
      <dc:creator>desert</dc:creator>
      <dc:date>2024-08-31T07:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Searching a shape by inputting attribute values in a GUI window using Python.</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1537216#M11447</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363945"&gt;@desert&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Thanks for sharing your script with the community.&lt;/P&gt;&lt;P&gt;While its true that currently advanced selections based on attributes can be done using the python scripting interface only, a basic search for attributes is available directly in the Scene Editor:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonasObertuefer_0-1726041829283.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/114771iAE175C93B0AB0F43/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JonasObertuefer_0-1726041829283.png" alt="JonasObertuefer_0-1726041829283.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;For more details about the feature checkout the online help:&lt;/P&gt;&lt;P&gt;&lt;A href="https://doc.arcgis.com/en/cityengine/latest/help/help-scene-editor.htm#ESRI_SECTION1_72124DD34BCA4140A4DA829930A84B98" target="_self"&gt;CityEngine Help: Scene Editor: Additional layer options&lt;/A&gt;&lt;/P&gt;&lt;P&gt;If you are interested in advanced search capabilities through a GUI interface, I encourage you to create a new post in the Ideas forum!&lt;/P&gt;&lt;P&gt;Cheers&lt;BR /&gt;Jonas&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2024 08:09:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1537216#M11447</guid>
      <dc:creator>JonasObertuefer</dc:creator>
      <dc:date>2024-09-11T08:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Searching a shape by inputting attribute values in a GUI window using Python.</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1537535#M11449</link>
      <description>&lt;P&gt;It seems I did something unnecessary without even thoroughly reading the manual I had checked before. I will carefully read the help section again. Thank you for pointing it out.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2024 20:34:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1537535#M11449</guid>
      <dc:creator>desert</dc:creator>
      <dc:date>2024-09-11T20:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Searching a shape by inputting attribute values in a GUI window using Python.</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1542375#M11463</link>
      <description>&lt;P&gt;I wouldn't say its unnecessary because you can do advanced filtering and selection using python. For instance using your script you can search for specific key/value pairs while the search bar in the Scene Editor will match everything with the entered name.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 09:41:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/searching-a-shape-by-inputting-attribute-values-in/m-p/1542375#M11463</guid>
      <dc:creator>JonasObertuefer</dc:creator>
      <dc:date>2024-09-25T09:41:58Z</dc:date>
    </item>
  </channel>
</rss>

