<?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: Adding multiple FeatureClasses &amp;amp; StandAloneTables to a map gives weird results in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-multiple-featureclasses-amp/m-p/1383942#M11113</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would recommend you put&amp;nbsp;QueuedTask.Run inside your methods&amp;nbsp;addFeatureClassToMap and&amp;nbsp;addTableToMap and delete one at the start. Sometimes using one QueuedTask.Run for few processes following each other does not work as expected.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Feb 2024 06:37:36 GMT</pubDate>
    <dc:creator>GKmieliauskas</dc:creator>
    <dc:date>2024-02-19T06:37:36Z</dc:date>
    <item>
      <title>Adding multiple FeatureClasses &amp; StandAloneTables to a map gives weird results</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-multiple-featureclasses-amp/m-p/1383601#M11111</link>
      <description>&lt;P&gt;Hi, I've created a button that create a new map and adds many layers and standAlone table to it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;After playing with it a bit, I found that it seams to work well. But when I looked at it more closely it's missing 7 or 8 of the 80 tables I've added. Those missing are random because from trying it many time, it`s not always the same tables that are missiing..&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here an extract of my code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;await QueuedTask.Run(async () =&amp;gt;
            {

                if (!checkPortalSignIn())
                {
                    showError(resPublishSAM.errRequireSigningInActiveServer);
                    return;
                }

                if (ext == ".sde")
                {
                    DatabaseConnectionFile dbcf = new DatabaseConnectionFile(new Uri(mainModule.Current.AquaGeoSettings.SDEConnectionFilePath));
                    pGeodatabase = new Geodatabase(dbcf);
                }
                else if (ext == ".gdb")
                {
                    FileGeodatabaseConnectionPath fileGeodatabaseConnectionPath = new FileGeodatabaseConnectionPath(new Uri(mainModule.Current.AquaGeoSettings.SDEConnectionFilePath));
                    pGeodatabase = new Geodatabase(fileGeodatabaseConnectionPath);
                }

                await addMapToTheProject(packageName);
                int total = 91;
                int c = 0;

                await addFeatureClassToMap("aga_AirValves", c++);
                updateProgress(resPublishSAM.Adding + "aga_AirValves", c, total);
                await addFeatureClassToMap("aga_ChamberAccess", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberAccess", c, total);
                await addFeatureClassToMap("aga_Chambers", c++);
                updateProgress(resPublishSAM.Adding + "aga_Chambers", c, total);
                await addFeatureClassToMap("aga_DrainValves", c++);
                updateProgress(resPublishSAM.Adding + "aga_DrainValves", c, total);
                await addFeatureClassToMap("aga_FireHydrants", c++);
                updateProgress(resPublishSAM.Adding + "aga_FireHydrants", c, total);
                await addFeatureClassToMap("aga_Nodes", c++);
                updateProgress(resPublishSAM.Adding + "aga_Nodes", c, total);
                await addFeatureClassToMap("aga_Pipes", c++);
                updateProgress(resPublishSAM.Adding + "aga_Pipes", c, total);
                await addFeatureClassToMap("aga_Reducers", c++);
                updateProgress(resPublishSAM.Adding + "aga_Reducers", c, total);
                await addFeatureClassToMap("aga_Reservoirs", c++);
                updateProgress(resPublishSAM.Adding + "aga_Reservoirs", c, total);
                await addFeatureClassToMap("aga_Valves", c++);
                updateProgress(resPublishSAM.Adding + "aga_Valves", c, total);
                await addFeatureClassToMap("aga_WaterMeters", c++);
                updateProgress(resPublishSAM.Adding + "aga_WaterMeters", c, total);
                await addFeatureClassToMap("aga_WaterPumps", c++);
                updateProgress(resPublishSAM.Adding + "aga_WaterPumps", c, total);
                await addFeatureClassToMap("ags_AccessPoints", c++);
                updateProgress(resPublishSAM.Adding + "ags_AccessPoints", c, total);
                await addFeatureClassToMap("ags_Sections", c++);
                updateProgress(resPublishSAM.Adding + "ags_Sections", c, total);
                await addTableToMap("aga_ChamberCrossSections", "aga_ChamberCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberCrossSections", c, total);
                await addTableToMap("aga_ChamberDefs", "aga_ChamberDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberDefs", c, total);
                await addTableToMap("aga_ChamberInspectionPaths", "aga_ChamberInspectionPaths", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberInspectionPaths", c, total);
                await addTableToMap("aga_ChamberManufacturers", "aga_ChamberManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberManufacturers", c, total);
                await addTableToMap("aga_ChamberModels", "aga_ChamberModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberModels", c, total);
                await addTableToMap("aga_ChamberParameters", "aga_ChamberParameters", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberParameters", c, total);
                await addTableToMap("aga_ChamberPriorities", "aga_ChamberPriorities", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberPriorities", c, total);
                await addTableToMap("aga_ChamberReportDefs", "aga_ChamberReportDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberReportDefs", c, total);
                await addTableToMap("aga_ChamberReportDefTypes", "aga_ChamberReportDefTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberReportDefTypes", c, total);
                await addTableToMap("aga_ChamberWorkSheets", "aga_ChamberWorkSheets", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberWorkSheets", c, total);
                await addTableToMap("aga_FHCrossSections", "aga_FHCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHCrossSections", c, total);
                await addTableToMap("aga_FHDefs", "aga_FHDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHDefs", c, total);
                await addTableToMap("aga_FHInspectionPaths", "aga_FHInspectionPaths", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHInspectionPaths", c, total);
                await addTableToMap("aga_FHManufacturers", "aga_FHManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHManufacturers", c, total);
                await addTableToMap("aga_FHModels", "aga_FHModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHModels", c, total);
                await addTableToMap("aga_FHNutModels", "aga_FHNutModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHNutModels", c, total);
                await addTableToMap("aga_FHOtherModels", "aga_FHOtherModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHOtherModels", c, total);
                await addTableToMap("aga_FHOtherModelValues", "aga_FHOtherModelValues", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHOtherModelValues", c, total);
                await addTableToMap("aga_FHOutletModels", "aga_FHOutletModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHOutletModels", c, total);
                await addTableToMap("aga_FHParameters", "aga_FHParameters", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHParameters", c, total);
                await addTableToMap("aga_FHPriorities", "aga_FHPriorities", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHPriorities", c, total);
                await addTableToMap("aga_FHReportDefs", "aga_FHReportDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHReportDefs", c, total);
                await addTableToMap("aga_FHReportDefTypes", "aga_FHReportDefTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHReportDefTypes", c, total);
                await addTableToMap("aga_FHWorkSheets", "aga_FHWorkSheets", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHWorkSheets", c, total);
                await addTableToMap("aga_Materials", "aga_Materials", c++);
                updateProgress(resPublishSAM.Adding + "aga_Materials", c, total);
                await addTableToMap("aga_MeterTypes", "aga_MeterTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_MeterTypes", c, total);
                await addTableToMap("aga_PipeClasses", "aga_PipeClasses", c++);
                updateProgress(resPublishSAM.Adding + "aga_PipeClasses", c, total);
                await addTableToMap("aga_PIVCrossSections", "aga_PIVCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_PIVCrossSections", c, total);
                await addTableToMap("aga_PIVManufacturers", "aga_PIVManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_PIVManufacturers", c, total);
                await addTableToMap("aga_PIVModels", "aga_PIVModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_PIVModels", c, total);
                await addTableToMap("aga_Relinings", "aga_Relinings", c++);
                updateProgress(resPublishSAM.Adding + "aga_Relinings", c, total);
                await addTableToMap("aga_RoadCenters", "aga_RoadCenters", c++);
                updateProgress(resPublishSAM.Adding + "aga_RoadCenters", c, total);
                await addTableToMap("aga_Sectors", "aga_Sectors", c++);
                updateProgress(resPublishSAM.Adding + "aga_Sectors", c, total);
                await addTableToMap("aga_ServiceBoxCrossSections", "aga_ServiceBoxCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_ServiceBoxCrossSections", c, total);
                await addTableToMap("aga_ServiceBoxManufacturers", "aga_ServiceBoxManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_ServiceBoxManufacturers", c, total);
                await addTableToMap("aga_ServiceBoxModels", "aga_ServiceBoxModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ServiceBoxModels", c, total);
                await addTableToMap("aga_UsageTypes", "aga_UsageTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_UsageTypes", c, total);
                await addTableToMap("aga_ValveAccess", "aga_ValveAccess", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveAccess", c, total);
                await addTableToMap("aga_ValveBox", "aga_ValveBox", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveBox", c, total);
                await addTableToMap("aga_ValveBoxCrossSections", "aga_ValveBoxCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveBoxCrossSections", c, total);
                await addTableToMap("aga_ValveBoxManufacturers", "aga_ValveBoxManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveBoxManufacturers", c, total);
                await addTableToMap("aga_ValveBoxModels", "aga_ValveBoxModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveBoxModels", c, total);
                await addTableToMap("aga_ValveDefs", "aga_ValveDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveDefs", c, total);
                await addTableToMap("aga_ValveInspectionPaths", "aga_ValveInspectionPaths", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveInspectionPaths", c, total);
                await addTableToMap("aga_ValveModelCrossSections", "aga_ValveModelCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveModelCrossSections", c, total);
                await addTableToMap("aga_ValveModelManufacturers", "aga_ValveModelManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveModelManufacturers", c, total);
                await addTableToMap("aga_ValveModels", "aga_ValveModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveModels", c, total);
                await addTableToMap("aga_ValveNutModels", "aga_ValveNutModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveNutModels", c, total);
                await addTableToMap("aga_ValveParameters", "aga_ValveParameters", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveParameters", c, total);
                await addTableToMap("aga_ValvePriorities", "aga_ValvePriorities", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValvePriorities", c, total);
                await addTableToMap("aga_ValveReportDefs", "aga_ValveReportDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveReportDefs", c, total);
                await addTableToMap("aga_ValveReportDefTypes", "aga_ValveReportDefTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveReportDefTypes", c, total);
                await addTableToMap("aga_ValveWorkSheets", "aga_ValveWorkSheets", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveWorkSheets", c, total);
                await addTableToMap("agc_aquaGeoSettings", "agc_aquaGeoSettings", c++);
                updateProgress(resPublishSAM.Adding + "agc_aquaGeoSettings", c, total);
                await addTableToMap("agc_Employees", "agc_Employees", c++);
                updateProgress(resPublishSAM.Adding + "agc_Employees", c, total);
                await addTableToMap("agc_streets", "agc_streets", c++);
                updateProgress(resPublishSAM.Adding + "agc_streets", c, total);
                await addTableToMap("ags_Canlite_Field_Job", "ags_Canlite_Field_Job", c++);
                updateProgress(resPublishSAM.Adding + "ags_Canlite_Field_Job", c, total);
                await addTableToMap("ags_Canlite_Field_Job_Events", "ags_Canlite_Field_Job_Events", c++);
                updateProgress(resPublishSAM.Adding + "ags_Canlite_Field_Job_Events", c, total);
                await addTableToMap("ags_Code_Substitutions", "ags_Code_Substitutions", c++);
                updateProgress(resPublishSAM.Adding + "ags_Code_Substitutions", c, total);
                await addTableToMap("ags_MH_Conditions", "ags_MH_Conditions", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Conditions", c, total);
                await addTableToMap("ags_MH_Conditions_Media", "ags_MH_Conditions_Media", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Conditions_Media", c, total);
                await addTableToMap("ags_MH_Connections", "ags_MH_Connections", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Connections", c, total);
                await addTableToMap("ags_MH_Connections_Media", "ags_MH_Connections_Media", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Connections_Media", c, total);
                await addTableToMap("ags_MH_Inspections", "ags_MH_Inspections", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Inspections", c, total);
                await addTableToMap("ags_MH_Inspections_Media", "ags_MH_Inspections_Media", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Inspections_Media", c, total);
                await addTableToMap("ags_PACP_Conditions", "ags_PACP_Conditions", c++);
                updateProgress(resPublishSAM.Adding + "ags_PACP_Conditions", c, total);
                await addTableToMap("ags_PACP_Inspections", "ags_PACP_Inspections", c++);
                updateProgress(resPublishSAM.Adding + "ags_PACP_Inspections", c, total);
                await addTableToMap("ags_PACP_Media_Conditions", "ags_PACP_Media_Conditions", c++);
                updateProgress(resPublishSAM.Adding + "ags_PACP_Media_Conditions", c, total);
                await addTableToMap("ags_PACP_Media_Inspections", "ags_PACP_Media_Inspections", c++);
                updateProgress(resPublishSAM.Adding + "ags_PACP_Media_Inspections", c, total);
                await addTableToMap("ags_Pipe_Records", "ags_Pipe_Records", c++);
                updateProgress(resPublishSAM.Adding + "ags_Pipe_Records", c, total);
                await addTableToMap("ags_Segments", "ags_Segments", c++);
                updateProgress(resPublishSAM.Adding + "ags_Segments", c, total);
                await addTableToMap("ags_WorkOrder_Categories", "ags_WorkOrder_Categories", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrder_Categories", c, total);
                await addTableToMap("ags_WorkOrder_Config", "ags_WorkOrder_Config", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrder_Config", c, total);
                await addTableToMap("ags_WorkOrder_CustomFields", "ags_WorkOrder_CustomFields", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrder_CustomFields", c, total);
                await addTableToMap("ags_WorkOrders", "ags_WorkOrders", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrders", c, total);
                await addTableToMap("ags_WorkOrders_Manholes", "ags_WorkOrders_Manholes", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrders_Manholes", c, total);
                await addTableToMap("ags_WorkOrders_Sections", "ags_WorkOrders_Sections", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrders_Sections", c, total);

                StringBuilder sb = new StringBuilder();
                await publishMapToPortal(packageName, settingsVM, sb);

                success = true;
            }, progressor: WindowService.ProgressorSource.Progressor);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then the method I use:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;private async Task addFeatureClassToMap(string fcName, int index)
        {
            pMapDrawn = false;
            FeatureClass fc = pGeodatabase.OpenDataset&amp;lt;FeatureClass&amp;gt;(fcName);
            LayerFactory.Instance.CreateLayer(fc.GetPath(), MapView.Active.Map, index, fcName);
            await WaitForMapToBeDrawn();
        }

        private async Task addTableToMap(string tableName, string layerName, int index)
        {
            tableAdded = false;
            Table tbl = pGeodatabase.OpenDataset&amp;lt;Table&amp;gt;(tableName);
            StandaloneTableFactory.Instance.CreateStandaloneTable(tbl.GetPath(), MapView.Active.Map, index, layerName);
            await WaitForTableAdded();
        }&lt;/LI-CODE&gt;&lt;P&gt;I found that I have better results if I wait for Arcgis to add the layers and table to the map before adding the next one. I'm using those event to do that:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;            ArcGIS.Desktop.Mapping.Events.DrawCompleteEvent.Subscribe(OnDrawComplete);
            ArcGIS.Desktop.Mapping.Events.StandaloneTablesAddedEvent.Subscribe(OnTableAdded);&lt;/LI-CODE&gt;&lt;LI-CODE lang="c"&gt;        private async Task&amp;lt;bool&amp;gt; WaitForTableAdded()
        {
            int count = 0;
            while (!tableAdded)
            {
                await Task.Delay(500);
                count++;

                if (count &amp;gt; 20)
                {
                    WindowService.DoEvents();
                    return false;
                }
            }
            WindowService.DoEvents();
            return true;
        }

        private async Task&amp;lt;bool&amp;gt; WaitForMapToBeDrawn()
        {
            int count = 0;
            // waiting for the map to be drawn
            while (!pMapDrawn)
            {
                await Task.Delay(500);
                count++;

                if (count &amp;gt; 20)
                {
                    WindowService.DoEvents();
                    return false;
                }
            }
            WindowService.DoEvents();
            return true;
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But even with that, instead of having 90 layers and tables, i get 86, 88, it varies..&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help please?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 19:50:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-multiple-featureclasses-amp/m-p/1383601#M11111</guid>
      <dc:creator>PierreMasson</dc:creator>
      <dc:date>2024-02-16T19:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple FeatureClasses &amp; StandAloneTables to a map gives weird results</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-multiple-featureclasses-amp/m-p/1383942#M11113</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would recommend you put&amp;nbsp;QueuedTask.Run inside your methods&amp;nbsp;addFeatureClassToMap and&amp;nbsp;addTableToMap and delete one at the start. Sometimes using one QueuedTask.Run for few processes following each other does not work as expected.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 06:37:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/adding-multiple-featureclasses-amp/m-p/1383942#M11113</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2024-02-19T06:37:36Z</dc:date>
    </item>
  </channel>
</rss>

