<?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: Cannot Add FeatureClass from GeoDatabase in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125832#M9808</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It looks like you're trying to add a Feature Layer directly to the table of contents in ArcMap; I'm not 100% sure you can do that.&amp;nbsp; Is there a specific reason why you're creating a feature layer from your feature class?&amp;nbsp; If you're open to doing so, please try the following?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeFeatureLayer_management(FeatureClassToAdd,tempLayer)&amp;nbsp; &lt;STRONG&gt;-- remove this line&lt;/STRONG&gt;
addLayer = arcpy.Layer(FeatureClassToAdd) &lt;STRONG&gt;-- modify "tempLayer" to FeatureClassToAdd&lt;/STRONG&gt;
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.RefreshTOC()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know if this works for you or not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: Ok, I did some research and I think your approach to using a feature layer might in fact be correct.&amp;nbsp; That being said, if my suggestion above doesn't work then you might try this as an alternative:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;GeoDatabaseName = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurementsDeep_GroundwaterElevation_Daily_Contours_20130625_20120731.gdb"&amp;nbsp; &lt;STRONG&gt;-- change the \ slash to a / slash&lt;/STRONG&gt;

FeatureClassToAdd = os.path.join(GeoDatabaseName,"AllPoints")&amp;nbsp; &lt;STRONG&gt;-- it looks like you are appending "AllPoints" to the geodatabase full path; is "AllPoints" your feature class name?&amp;nbsp; I think you might need a slash between the ".gdb" and the "AllPoints" for this portion of the code.&amp;nbsp; Try modifying "AllPoints" to "/AllPoints" or "\AllPoints".&lt;/STRONG&gt;
 
 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 07:09:40 GMT</pubDate>
    <dc:creator>WilliamCraft</dc:creator>
    <dc:date>2021-12-11T07:09:40Z</dc:date>
    <item>
      <title>Cannot Add FeatureClass from GeoDatabase</title>
      <link>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125831#M9807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm still fairly new to using the arcpy.mapping functions.&amp;nbsp; I want to add a FeatureClass to my map document which is open.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In looking at other forum threads and reading help, I tried the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import arcpy.mapping import os&amp;nbsp; GeoDatabaseName = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurementsDeep_GroundwaterElevation_Daily_Contours_20130625_20120731.gdb"&amp;nbsp; ##Reference the map document in memory. mxd = arcpy.mapping.MapDocument(r"G:\Documents\GIS\HydstraData\Contours_20131223.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] print df&amp;nbsp; FeatureClassToAdd = os.path.join(GeoDatabaseName,"AllPoints") print FeatureClassToAdd tempLayer = "layer" ## Make a layer from the feature class arcpy.MakeFeatureLayer_management(FeatureClassToAdd,tempLayer) addLayer = arcpy.Layer(tempLayer) arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE") arcpy.RefreshTOC()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is the result I get back in my Python Shell windowing when I run the script in IDLE:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;geoprocessing Data Frame object object at 0x02C57368&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurementsDeep_GroundwaterElevation_Daily_Contours_20130625_20120731.gdb\AllPoints&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "G:/Documents/GIS/HydstraData/UpdateMxd.py", line 24, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.Layer(tempLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: 'module' object has no attribute 'Layer'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions?&amp;nbsp; Thanks for any help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 21:23:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125831#M9807</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2013-12-23T21:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Add FeatureClass from GeoDatabase</title>
      <link>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125832#M9808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It looks like you're trying to add a Feature Layer directly to the table of contents in ArcMap; I'm not 100% sure you can do that.&amp;nbsp; Is there a specific reason why you're creating a feature layer from your feature class?&amp;nbsp; If you're open to doing so, please try the following?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeFeatureLayer_management(FeatureClassToAdd,tempLayer)&amp;nbsp; &lt;STRONG&gt;-- remove this line&lt;/STRONG&gt;
addLayer = arcpy.Layer(FeatureClassToAdd) &lt;STRONG&gt;-- modify "tempLayer" to FeatureClassToAdd&lt;/STRONG&gt;
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.RefreshTOC()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know if this works for you or not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: Ok, I did some research and I think your approach to using a feature layer might in fact be correct.&amp;nbsp; That being said, if my suggestion above doesn't work then you might try this as an alternative:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;GeoDatabaseName = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurementsDeep_GroundwaterElevation_Daily_Contours_20130625_20120731.gdb"&amp;nbsp; &lt;STRONG&gt;-- change the \ slash to a / slash&lt;/STRONG&gt;

FeatureClassToAdd = os.path.join(GeoDatabaseName,"AllPoints")&amp;nbsp; &lt;STRONG&gt;-- it looks like you are appending "AllPoints" to the geodatabase full path; is "AllPoints" your feature class name?&amp;nbsp; I think you might need a slash between the ".gdb" and the "AllPoints" for this portion of the code.&amp;nbsp; Try modifying "AllPoints" to "/AllPoints" or "\AllPoints".&lt;/STRONG&gt;
 
 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:09:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125832#M9808</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2021-12-11T07:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Add FeatureClass from GeoDatabase</title>
      <link>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125833#M9809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply; much appreciated.&amp;nbsp; What I REALLY want to do is simply add the Featureclass that resides in my GeoDatabase.&amp;nbsp; In reading other threads (such as &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/42567-Insert-Feature-Class-using-arcpy" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/42567-Insert-Feature-Class-using-arcpy&lt;/A&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;it seemed fairly straight forward.&amp;nbsp; That thread said:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Use makefeaturelayer_management() and use the Layer object to add the layer object to the TOC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#... other logic
tempLayer = "layer"
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management("C:/data/mexico.gdb/cities",tempLayer)
addLayer = arcpy.Layer(tempLayer)
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.RefreshTOC()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But for some reason, I can't quite make it work for me.&amp;nbsp; The ultimate goal is to add in a few feature classes, symbolize them on a previously created and saved ".lyr" file and then do some other processing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:09:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125833#M9809</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2021-12-11T07:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Add FeatureClass from GeoDatabase</title>
      <link>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125834#M9810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As far as the part where you wish to add the feature class to your TOC, please refer back to my post and run through the various suggestions.&amp;nbsp; Let me know if any of those work.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 22:24:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125834#M9810</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2013-12-23T22:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Add FeatureClass from GeoDatabase</title>
      <link>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125835#M9811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The ultimate goal is to add in a few feature classes, symbolize them on a previously created and saved ".lyr" file and then do some other processing.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I will also say that, if your ultimate goal is to perform data processing, then you are not required to add your data to a map document.&amp;nbsp; You can use the GP tools via arcpy and output the resulting data directly to the desired format and skip the map document entirely.&amp;nbsp; However, if you require the map document for analysis and cartographic purposes, then disregard this specific post.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 22:32:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125835#M9811</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2013-12-23T22:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Add FeatureClass from GeoDatabase</title>
      <link>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125836#M9812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;crafty762,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks very much for your comments, but I'm still struggling with this.&amp;nbsp; I simplified the code by putting a map document and a stand-alone shapefile in my C:\Temp directory, so I wasn't dealing with the convoluted long directory path.&amp;nbsp; The code below runs with no errors, but I'm not seeing my TOC populated with the shapefile after it runs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import arcpy.mapping
import os

arcpy.env.workspace = r"C:\Temp"

##Reference the map document in memory.
mxd = arcpy.mapping.MapDocument(r"C:\Temp\Test.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
print df

NewLayer = arcpy.mapping.Layer("AllContours3D.shp")
print NewLayer
arcpy.mapping.AddLayer(df, NewLayer, "AUTO_ARRANGE")
arcpy.RefreshTOC()&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;During development, I am writing this code with IDLE, then hitting the "Run" menu and looking at my results in the Python Shell window.&amp;nbsp; I DO have my Test.mxd open while running it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next, I actually saved the Python code as a script, added it to my personal toolbox, and ran the script from WITHIN my Test.mxd.&amp;nbsp; In either case my TOC does not refresh.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I DO want to see the map updated because this script is ultimately meant to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;Add groundwater Contour Lines.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Symbolize Contour Lines from previously saved layer file.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Make the Contour Lines time-enabled.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Run the Time-Slider viewing the contours on a daily basis.&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;BR /&gt;&lt;SPAN&gt;I've manually done the steps above in a map document and everything works fine.&amp;nbsp; Actually, it's pretty intense to see the groundwater contours wiggle all over the map over a 90 day period (very useful for groundwater extraction analysis).&amp;nbsp; I just want to fully automate the process so other staff can more easily run the model.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:09:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125836#M9812</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2021-12-11T07:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Add FeatureClass from GeoDatabase</title>
      <link>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125837#M9813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I FINALLY got this to work!&amp;nbsp; The syntax for adding a Featureclass was correct.&amp;nbsp; I believe my problem was that I wasn't referring to the "CURRENT" map document.&amp;nbsp; The code below works fine and the TOC is refreshed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import arcpy.mapping import os&amp;nbsp; arcpy.env.workspace = r"C:\Temp"&amp;nbsp; ##Reference the Current map document. mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd)[0] print df&amp;nbsp; NewLayer = arcpy.mapping.Layer("AllContours3D.shp") print NewLayer arcpy.mapping.AddLayer(df, NewLayer, "AUTO_ARRANGE") arcpy.RefreshTOC()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So what have I learned?&amp;nbsp; My Python coding so far has involved only geoprocessing functions (NO mapping functions), and I didn't need a session of ArcMap open.&amp;nbsp; I could just run the script in IDLE, then open ArcCatalog to view the results.&amp;nbsp; Now that I am working with mapping functions, I NEED to have a map document open and run the Python script WITHIN the ArcMap session?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does that make sense?&amp;nbsp; Thanks for your input!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon Mulder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;California Department of Water Resources&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Dec 2013 09:26:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125837#M9813</guid>
      <dc:creator>JonathanMulder</dc:creator>
      <dc:date>2013-12-24T09:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Add FeatureClass from GeoDatabase</title>
      <link>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125838#M9814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Makes sense, yes.&amp;nbsp; That's kind of why I made my comment above about requiring the map document versus not.&amp;nbsp; I'm very glad that you got things working.&amp;nbsp; Good luck and happy holidays.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Dec 2013 12:00:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-add-featureclass-from-geodatabase/m-p/125838#M9814</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2013-12-24T12:00:20Z</dc:date>
    </item>
  </channel>
</rss>

