<?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: Populate - Folder Connection, Custom Style, Custom Tools in new project in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1221388#M8883</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;For toolbox try this code:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;                string paToolBoxPath = "C:\\Data\\CustomTools.tbx";
                var itemTool = ItemFactory.Instance.Create(paToolBoxPath) as IProjectItem;
                await QueuedTask.Run(() =&amp;gt;
                {
                    Project.Current.AddItem(itemTool);
                });

                if (FavoritesManager.Current.CanAddAsFavorite(itemTool as Item))
                {
                    FavoritesManager.Current.AddFavorite(itemTool as Item);
                }&lt;/LI-CODE&gt;&lt;P&gt;Last code sample works for folder connections and styles too. Maybe this way is right to add items to project and favorites&lt;/P&gt;</description>
    <pubDate>Thu, 13 Oct 2022 05:36:43 GMT</pubDate>
    <dc:creator>GKmieliauskas</dc:creator>
    <dc:date>2022-10-13T05:36:43Z</dc:date>
    <item>
      <title>Populate - Folder Connection, Custom Style, Custom Tools in new project</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1220443#M8871</link>
      <description>&lt;P&gt;Goal - Create an add-in button that populates a new project with a Folder Connection, a Custom Style and a Custom Tools&lt;/P&gt;&lt;P&gt;Lines 3 through 9 below run correctly and were copied from:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-content" target="_blank"&gt;ProSnippets Content · Esri/arcgis-pro-sdk Wiki (github.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;After modifying the example code to work with a "Style" instead of a "Folder Connection".&amp;nbsp; An exception is thrown on line 16...&amp;nbsp;&lt;/P&gt;&lt;P&gt;System.NullReferenceException&lt;BR /&gt;Message=Object reference not set to an instance of an object.&lt;/P&gt;&lt;P&gt;Thus, if I read the exception correctly, an object of StyleProjectItem is not instantiated or the return is left as null.&lt;/P&gt;&lt;P&gt;Reading through the API documentation...&amp;nbsp;&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic15850.html" target="_blank"&gt;IProjectItem Interface—ArcGIS&amp;nbsp;&lt;/A&gt;&lt;FONT color="#0079c1"&gt;&lt;U&gt;Pro The&lt;/U&gt;&lt;/FONT&gt;&amp;nbsp; Overview -&amp;gt; Remarks state, "&lt;SPAN&gt;These classes also follow a convention that includes "ProjectItem" as part of their name"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Based upon the stated convention... it appears like StyleProjectItem should be instantiated&amp;nbsp;correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override async void OnClick()
        {
            string folderPath = "C:\\Data";
            var folder = await QueuedTask.Run(() =&amp;gt;
            {
                var itemFolder = ItemFactory.Instance.Create(folderPath) as IProjectItem;
                return Project.Current.AddItem(itemFolder) ? itemFolder as FolderConnectionProjectItem : null;
            });
            FavoritesManager.Current.AddFavorite(folder);

            string stylePath = "C:\\Data\\CustomStyles.stylx";

            var style = await QueuedTask.Run(() =&amp;gt;
            {
                var itemStyle = ItemFactory.Instance.Create(stylePath) as IProjectItem;
                return Project.Current.AddItem(itemStyle) ? itemStyle as StyleProjectItem : null;
            });
            FavoritesManager.Current.AddFavorite(style);

            string paToolBoxPath = "C:\\Data\\CustomTools.tbx";
            var toolBox = await QueuedTask.Run(() =&amp;gt;
            {
                var itemTool = ItemFactory.Instance.Create(paToolBoxPath) as IProjectItem;
                return Project.Current.AddItem(itemTool) ? itemTool as GeoprocessingProjectItem : null;
            });
            FavoritesManager.Current.AddFavorite(toolBox);
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 17:24:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1220443#M8871</guid>
      <dc:creator>JeromeHaaland</dc:creator>
      <dc:date>2022-10-10T17:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Populate - Folder Connection, Custom Style, Custom Tools in new project</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1220584#M8872</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Style needs a little bit different workflow:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;                string stylePath = "C:\\Data\\CustomStyles.stylx";

                await QueuedTask.Run(() =&amp;gt;
                {
                    Project.Current.AddStyle(stylePath);
                });

                var itemStyle = ItemFactory.Instance.Create(stylePath);
                FavoritesManager.Current.AddFavorite(itemStyle);&lt;/LI-CODE&gt;&lt;P&gt;Another one thing. If you return null from QueuedTask.Run then you need to check result for it is not null before adding to favorites&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 06:03:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1220584#M8872</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2022-10-11T06:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Populate - Folder Connection, Custom Style, Custom Tools in new project</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1221218#M8880</link>
      <description>&lt;P&gt;Gintautas,&lt;/P&gt;&lt;P&gt;Thank You... the above code works well to add a style.&lt;/P&gt;&lt;P&gt;However... there does not appear to be a similar method to add a custom toolbox.&amp;nbsp; As I am trying to do in lines 20 through 26 of my code.&lt;/P&gt;&lt;P&gt;Do you have a suggestion to add a custom toolbox with C# code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 17:56:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1221218#M8880</guid>
      <dc:creator>JeromeHaaland</dc:creator>
      <dc:date>2022-10-12T17:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Populate - Folder Connection, Custom Style, Custom Tools in new project</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1221388#M8883</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;For toolbox try this code:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;                string paToolBoxPath = "C:\\Data\\CustomTools.tbx";
                var itemTool = ItemFactory.Instance.Create(paToolBoxPath) as IProjectItem;
                await QueuedTask.Run(() =&amp;gt;
                {
                    Project.Current.AddItem(itemTool);
                });

                if (FavoritesManager.Current.CanAddAsFavorite(itemTool as Item))
                {
                    FavoritesManager.Current.AddFavorite(itemTool as Item);
                }&lt;/LI-CODE&gt;&lt;P&gt;Last code sample works for folder connections and styles too. Maybe this way is right to add items to project and favorites&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 05:36:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1221388#M8883</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2022-10-13T05:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Populate - Folder Connection, Custom Style, Custom Tools in new project</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1221718#M8887</link>
      <description>&lt;P&gt;Gintautas,&lt;/P&gt;&lt;P&gt;Excellent help.&amp;nbsp; The last solution was the best.&amp;nbsp; It is better than the example provided by ESRI because similar code works for a Folder Connect, Style and Toolbox.&lt;/P&gt;&lt;P&gt;I did change my code to use the last solution for all 3 items.&lt;/P&gt;&lt;P&gt;Nice and elegant solution.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 18:58:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/populate-folder-connection-custom-style-custom/m-p/1221718#M8887</guid>
      <dc:creator>JeromeHaaland</dc:creator>
      <dc:date>2022-10-13T18:58:30Z</dc:date>
    </item>
  </channel>
</rss>

