<?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: Add Feature Class to Current Pro Project Via Script Tool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100592#M62528</link>
    <description>&lt;P&gt;dir .... often uncovers the unincluded&lt;/P&gt;&lt;LI-CODE lang="python"&gt;proj = r"C:\arcpro_npg\npg\Project_npg\npGeom.aprx"
aprx = arcpy.mp.ArcGISProject(proj)

dir(aprx)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
 '__format__', '__from_scripting_arc_object__', '__ge__', '__getattribute__',
 '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__',
 '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
 '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
 '__weakref__', '_arc_object',
 'activeMap',
 'activeView',
 'dateSaved',
 'defaultGeodatabase',
 'defaultToolbox',
 'documentVersion',
 'filePath',
 'homeFolder',
 'importDocument',
 'listBrokenDataSources',
 'listColorRamps',
 'listLayouts',
 'listMaps',
 'listReports',
 'metadata',
 'save',
 'saveACopy',
 'updateConnectionProperties']&lt;/LI-CODE&gt;&lt;P&gt;.... help on those properties and methods is quite limited though&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print(aprx.save.__doc__)
ArcGISProject.save()

           Saves changes to an ArcGISProject ( .aprx ).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Sep 2021 22:57:48 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-09-21T22:57:48Z</dc:date>
    <item>
      <title>Add Feature Class to Current Pro Project Via Script Tool</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100065#M62508</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I replied to &lt;A href="https://community.esri.com/t5/arcgis-pro-questions/adding-feature-class-to-map-script/m-p/164053#M7408" target="_self"&gt;this post&lt;/A&gt; where the user had the same issue I'm experiencing. Since it was a Pro question I decided to repost here in Python.&lt;/P&gt;&lt;P&gt;The problem I'm facing involves my custom script tool not adding a feature class to an open Pro project. I'm using Pro 2.8.&lt;/P&gt;&lt;P&gt;Working from a notebook, this successfully adds a feature class to the map.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os
data = r'path\to\BaseLayer_Processed_Elementary_08302021_clip'
arcpy.env.addOutputsToMap = True 

try:

arcpy.management.MakeFeatureLayer(data, data) 
    
except:
    print(arcpy.GetMessages())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, according to the docs the above only creates a temp layer in the map. So, unless you save the map or export the layer to a feature class it won't be saved. So, I tried the below script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os
data = r'path\to\BaseLayer_Processed_Elementary_08302021_clip'
arcpy.env.addOutputsToMap = True 

try:

    # Write the selected features to a new featureclass
    arcpy.CopyFeatures_management(data, os.path.basename(data))
    
except:
    print(arcpy.GetMessages())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both scripts work to add a feature class to the map. However, when I convert to a script tool to run within pro it runs successfully, but nothing is added to the map.&lt;/P&gt;&lt;P&gt;Tool version of the script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os

#input feature class from model. It will be added to the map.
data = arcpy.GetParameterAsText(0)
arcpy.env.addOutputsToMap = True
arcpy.AddMessage(f'adding to map: {data}') 

try:

    #Copies features from the input feature class or layer to a new feature class.
    arcpy.CopyFeatures_management(data, os.path.basename(data))
    
except:
    arcpy.AddMessage(arcpy.GetMessage())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tool interface:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JaredPilbeam2_0-1632166144459.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/23412iEEA3B8446A011538/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JaredPilbeam2_0-1632166144459.png" alt="JaredPilbeam2_0-1632166144459.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 19:47:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100065#M62508</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-09-20T19:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Add Feature Class to Current Pro Project Via Script Tool</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100083#M62511</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="add_results_to_map2.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/23420iF6BBB9BE011BA1AC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="add_results_to_map2.png" alt="add_results_to_map2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;this is checked on as well?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 20:13:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100083#M62511</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-09-20T20:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Add Feature Class to Current Pro Project Via Script Tool</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100098#M62512</link>
      <description>&lt;P&gt;Dan,&lt;/P&gt;&lt;P&gt;Didn't realize that was there. It's checked on, anyway.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 21:12:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100098#M62512</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-09-20T21:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Add Feature Class to Current Pro Project Via Script Tool</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100119#M62513</link>
      <description>&lt;P&gt;I do something similar with the code below to add a layer to the map that is currently open in ArcGIS Pro.&amp;nbsp; My code runs from a python toolbox - not sure if it applies to what your are doing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;        aprx = arcpy.mp.ArcGISProject('CURRENT')
        current_map = aprx.activeMap
        current_map.addDataFromPath(&amp;lt;path to feature class&amp;gt;)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 22:13:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100119#M62513</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2021-09-20T22:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Add Feature Class to Current Pro Project Via Script Tool</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100137#M62520</link>
      <description>&lt;P&gt;I think Don has the solution/work-around, I think notebooks rely on this approach rather than the checkbox for project defaults.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do vaguely remember data not being added to the map before, which I thought was resolved, but it does make sense since a toolbox tool really doesn't know what the active project or active map is, particularly for toolboxes that reside in a different path that the project folder.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 23:15:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100137#M62520</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-09-20T23:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Add Feature Class to Current Pro Project Via Script Tool</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100280#M62527</link>
      <description>&lt;P&gt;That works. It makes sense that the script tool didn't know the map. Thanks for pointing that out. Nowhere did I come across &lt;EM&gt;.activeMap&lt;/EM&gt; in the help pages&lt;EM&gt;.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 13:54:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100280#M62527</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-09-21T13:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: Add Feature Class to Current Pro Project Via Script Tool</title>
      <link>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100592#M62528</link>
      <description>&lt;P&gt;dir .... often uncovers the unincluded&lt;/P&gt;&lt;LI-CODE lang="python"&gt;proj = r"C:\arcpro_npg\npg\Project_npg\npGeom.aprx"
aprx = arcpy.mp.ArcGISProject(proj)

dir(aprx)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
 '__format__', '__from_scripting_arc_object__', '__ge__', '__getattribute__',
 '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__',
 '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
 '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
 '__weakref__', '_arc_object',
 'activeMap',
 'activeView',
 'dateSaved',
 'defaultGeodatabase',
 'defaultToolbox',
 'documentVersion',
 'filePath',
 'homeFolder',
 'importDocument',
 'listBrokenDataSources',
 'listColorRamps',
 'listLayouts',
 'listMaps',
 'listReports',
 'metadata',
 'save',
 'saveACopy',
 'updateConnectionProperties']&lt;/LI-CODE&gt;&lt;P&gt;.... help on those properties and methods is quite limited though&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print(aprx.save.__doc__)
ArcGISProject.save()

           Saves changes to an ArcGISProject ( .aprx ).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 22:57:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-feature-class-to-current-pro-project-via/m-p/1100592#M62528</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-09-21T22:57:48Z</dc:date>
    </item>
  </channel>
</rss>

