<?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: Toolbox Python Script Dropdown Contains Duplicates in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/toolbox-python-script-dropdown-contains-duplicates/m-p/1382879#M69891</link>
    <description>&lt;P&gt;Hello, you can try to use a set in your list to remove duplicated values. Line 13:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    def initializeParameters(self):
        """Initialize parameters."""
        # Retrieve unique event IDs from the hosted feature layer
        aprx = arcpy.mp.ArcGISProject("CURRENT")
        lyr = aprx.listMaps()[0].listLayers()[0]  # Assuming the hosted feature layer is the first layer in the map
        event_ids = set()
        with arcpy.da.SearchCursor(lyr, "event_id") as cursor:
            for row in cursor:
                event_ids.add(row[0])
        
        # Populate the dropdown parameter with unique event IDs from the hosted feature layer
        sel_event_id = self.params[0]
        sel_event_id.filter.list = sorted(list(set(event_ids))) # Set Function Added

        # 2-9-24 THIS SECTION IS NOT BEING EXECUTED ALTHOUGH SCRIPT WORKING OK Print all event IDs retrieved from the hosted feature layer
        for event_id in event_ids:
            arcpy.AddMessage("Retrieved Event ID: {}".format(event_id))

        # Print the datasource for the hosted feature layer
        arcpy.AddMessage("Connected Hosted Feature Layer: {}".format(lyr.dataSource))

        # Print the datasource for the related table (tbl)
        tbl = aprx.listMaps()[0].listTables()[0]  # Assuming the related table is the first table in the map
        arcpy.AddMessage("Connected Related Table: {}".format(tbl.dataSource))
        return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2024 16:11:19 GMT</pubDate>
    <dc:creator>PedroCoutinhoMendonça</dc:creator>
    <dc:date>2024-02-15T16:11:19Z</dc:date>
    <item>
      <title>Toolbox Python Script Dropdown Contains Duplicates</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-python-script-dropdown-contains-duplicates/m-p/1381273#M69854</link>
      <description>&lt;P&gt;Hi. I'm using ArcGIS 3.2.&lt;BR /&gt;I added a new python script to the Toolbox that was created by Default in my new project.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Quick silent video of both scripts at work&lt;BR /&gt;&lt;A href="https://www.loom.com/share/9e7b72ee9a3448d18994a255ee68d91a?sid=cf199512-b146-49b7-b012-bf4eb819f333" target="_blank" rel="noopener"&gt;https://www.loom.com/share/9e7b72ee9a3448d18994a255ee68d91a?sid=cf199512-b146-49b7-b012-bf4eb819f333&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like for user to select from a dropdown, and have report generated.&lt;BR /&gt;Currently both scripts work for the purpose of generating reports, but&amp;nbsp;&lt;BR /&gt;1- One script has user entering event_id manually.&lt;BR /&gt;2- Second script has the dropdown, but duplicates appear.&amp;nbsp; I've tried everything only to still have the duplicates appear.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Any help is welcome and appreciated. I am open to your recommendations.&amp;nbsp;&lt;BR /&gt;I only need one script, sharing both to share my history and what brought me here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 20:22:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-python-script-dropdown-contains-duplicates/m-p/1381273#M69854</guid>
      <dc:creator>survey123_solutions</dc:creator>
      <dc:date>2024-02-12T20:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Toolbox Python Script Dropdown Contains Duplicates</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-python-script-dropdown-contains-duplicates/m-p/1382879#M69891</link>
      <description>&lt;P&gt;Hello, you can try to use a set in your list to remove duplicated values. Line 13:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    def initializeParameters(self):
        """Initialize parameters."""
        # Retrieve unique event IDs from the hosted feature layer
        aprx = arcpy.mp.ArcGISProject("CURRENT")
        lyr = aprx.listMaps()[0].listLayers()[0]  # Assuming the hosted feature layer is the first layer in the map
        event_ids = set()
        with arcpy.da.SearchCursor(lyr, "event_id") as cursor:
            for row in cursor:
                event_ids.add(row[0])
        
        # Populate the dropdown parameter with unique event IDs from the hosted feature layer
        sel_event_id = self.params[0]
        sel_event_id.filter.list = sorted(list(set(event_ids))) # Set Function Added

        # 2-9-24 THIS SECTION IS NOT BEING EXECUTED ALTHOUGH SCRIPT WORKING OK Print all event IDs retrieved from the hosted feature layer
        for event_id in event_ids:
            arcpy.AddMessage("Retrieved Event ID: {}".format(event_id))

        # Print the datasource for the hosted feature layer
        arcpy.AddMessage("Connected Hosted Feature Layer: {}".format(lyr.dataSource))

        # Print the datasource for the related table (tbl)
        tbl = aprx.listMaps()[0].listTables()[0]  # Assuming the related table is the first table in the map
        arcpy.AddMessage("Connected Related Table: {}".format(tbl.dataSource))
        return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 16:11:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-python-script-dropdown-contains-duplicates/m-p/1382879#M69891</guid>
      <dc:creator>PedroCoutinhoMendonça</dc:creator>
      <dc:date>2024-02-15T16:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Toolbox Python Script Dropdown Contains Duplicates</title>
      <link>https://community.esri.com/t5/python-questions/toolbox-python-script-dropdown-contains-duplicates/m-p/1385952#M69937</link>
      <description>&lt;P&gt;Hi, I guess you need to create a set first after you create the list. Then, you convert it to list&lt;/P&gt;&lt;P&gt;I tried to minimize the chaneg of your code&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def initializeParameters(self):
        """Initialize parameters."""
        try:
            # Define REST URLs for the main layer and related table
            main_layer_url = "https://services8.arcgis.com/CQeG4yN4mcOJaKOV/arcgis/rest/services/service_b4b3e49de39547628b85a73989096909/FeatureServer/0"
            related_table_url = "https://services8.arcgis.com/CQeG4yN4mcOJaKOV/arcgis/rest/services/service_b4b3e49de39547628b85a73989096909/FeatureServer/1"

            # Set the selected event ID parameter to populate dropdown
            sel_event_id  = [row[0] for row in arcpy.da.SearchCursor(main_layer_url, "event_id")]
            create_unique_sel_even_id = set(sel_event_id)
            self.params[0] = list(create_unique_sel_even_id)

            # Print all event IDs retrieved from the hosted feature layer
            event_ids = [row[0] for row in arcpy.da.SearchCursor(main_layer_url, "event_id")]
            for event_id in event_ids:
                arcpy.AddMessage("Retrieved Event ID: {}".format(event_id))

            # Print the datasource for the hosted feature layer
            lyr = arcpy.MakeFeatureLayer_management(main_layer_url, "Main_Layer")[0]
            arcpy.AddMessage("Connected Hosted Feature Layer: {}".format(lyr.dataSource))

            # Print the datasource for the related table
            tbl = arcpy.MakeTableView_management(related_table_url, "Related_Table")[0]
            arcpy.AddMessage("Connected Related Table: {}".format(tbl.dataSource))

        except Exception as e:
            arcpy.AddError("An error occurred during parameter initialization: {}".format(str(e)))

        return&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>Fri, 23 Feb 2024 12:26:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolbox-python-script-dropdown-contains-duplicates/m-p/1385952#M69937</guid>
      <dc:creator>AlexanderDanielPratama</dc:creator>
      <dc:date>2024-02-23T12:26:13Z</dc:date>
    </item>
  </channel>
</rss>

