<?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: Retrieving programatically added Project Items (Layouts) in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/retrieving-programatically-added-project-items/m-p/852222#M4307</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could listen to the Project Items changed event:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;                ProjectItemsChangedEvent&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Subscribe&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;args&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;
                &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
                    System&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Diagnostics&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Debug&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;WriteLine&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;$&lt;SPAN class="string token"&gt;@"{args.Action.ToString()} {args.ProjectItem.Title}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
                &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;false&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the 'Action' is 'Add' and 'args.ProjectItem' should be your newly added LayoutProjectItem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 10:30:03 GMT</pubDate>
    <dc:creator>Wolf</dc:creator>
    <dc:date>2021-12-12T10:30:03Z</dc:date>
    <item>
      <title>Retrieving programatically added Project Items (Layouts)</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/retrieving-programatically-added-project-items/m-p/852221#M4306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm developing an add-in that needs to programatically import a Layout from a PAGX file into a Project. The import itself is working fine, but I need to use the Layout object immediately after it is added. This becomes a problem when there are name collisions, given that Arc Pro automatically appends a number when a Layout with an existing name is added. I do have the unmodified name in memory (stored in a custom object), so when duplicate names are NOT an issue, I can "search" for the&amp;nbsp;new Layout with the call&lt;/P&gt;&lt;PRE&gt;Layout myNewLayout = Project.Current.GetItems&amp;lt;LayoutProjectItem&amp;gt;().FirstOrDefault(item =&amp;gt; item.Name == knownLayoutName).GetLayout();&lt;/PRE&gt;&lt;P&gt;When there is a name collision, however, this call just returns the Layout with the given name that existed pre-import (since the new Layout is now named something like "myNewLayout1").&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus far, the&amp;nbsp;only way I have found to get the correct LayoutProjectItem is to first find the latest SourceModifiedTime of all of the Project's LayoutProjectItems, and then filter on item.SourceModifiedTime == maxModifiedTime. This&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;seems to be working, but I don't actually know why...when I step through the code with the debugger, it seems that the SourceModifiedTime attribute for every LayoutProjectItem is just some default value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Part of the issue is that the actual import has to be done with ItemFactory.Instance.Create(), which returns an IProjectItem value. That value cannot be cast to a LayoutProjectItem, and from what I gather, the LayoutProjectItem doesn't even exist until Project.Current.AddItem() is called. The originally returned IProjectItem and the corresponding LayoutProjectItem don't have the same CacheID property, either, and other than SourceModifiedTime, I don't see any other distinguishing attributes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, once I make that call to AddItem(), is there a better way to retrieve exactly the Layout (or LayoutProjectItem) I just added? The fact that a Layout's unique identifier is its name seems to be the root of the issue here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2019 16:07:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/retrieving-programatically-added-project-items/m-p/852221#M4306</guid>
      <dc:creator>DavidLaMartina</dc:creator>
      <dc:date>2019-12-05T16:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving programatically added Project Items (Layouts)</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/retrieving-programatically-added-project-items/m-p/852222#M4307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could listen to the Project Items changed event:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;                ProjectItemsChangedEvent&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;Subscribe&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;args&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;
                &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
                    System&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Diagnostics&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Debug&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;WriteLine&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;$&lt;SPAN class="string token"&gt;@"{args.Action.ToString()} {args.ProjectItem.Title}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
                &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;false&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the 'Action' is 'Add' and 'args.ProjectItem' should be your newly added LayoutProjectItem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 10:30:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/retrieving-programatically-added-project-items/m-p/852222#M4307</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2021-12-12T10:30:03Z</dc:date>
    </item>
  </channel>
</rss>

