<?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 arcpy.mapping.AddLayer (SDE Feature Class) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455333#M35789</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When adding an ArcSDE Feature Class to an .mxd, it only shows the first 3 letters of the name in the TOC.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = "C:\\Users\\me\\AppData\\Roaming\ESRI\\Desktop10.1\\ArcCatalog\\mysdeserver.sde" &amp;nbsp;&amp;nbsp;&amp;nbsp; sdelist = arcpy.ListFeatureClasses() &amp;nbsp;&amp;nbsp;&amp;nbsp; for sdeFC in sdelist: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## locate the desired fc and add it to the TOC &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if sdeFC == 'GIS.THE_FEATURE_CLASS_NAME': &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sdeLyr = arcpy.mapping.Layer(sdeFC) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, sdeLyr, "BOTTOM") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above code adds the feature class but it adds it with the name "GIS".&amp;nbsp; Am I completely using the wrong method (I don't see any other way).&amp;nbsp; Solution?&amp;nbsp; Comments?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Apr 2013 18:31:48 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2013-04-17T18:31:48Z</dc:date>
    <item>
      <title>arcpy.mapping.AddLayer (SDE Feature Class)</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455333#M35789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When adding an ArcSDE Feature Class to an .mxd, it only shows the first 3 letters of the name in the TOC.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = "C:\\Users\\me\\AppData\\Roaming\ESRI\\Desktop10.1\\ArcCatalog\\mysdeserver.sde" &amp;nbsp;&amp;nbsp;&amp;nbsp; sdelist = arcpy.ListFeatureClasses() &amp;nbsp;&amp;nbsp;&amp;nbsp; for sdeFC in sdelist: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## locate the desired fc and add it to the TOC &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if sdeFC == 'GIS.THE_FEATURE_CLASS_NAME': &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sdeLyr = arcpy.mapping.Layer(sdeFC) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, sdeLyr, "BOTTOM") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above code adds the feature class but it adds it with the name "GIS".&amp;nbsp; Am I completely using the wrong method (I don't see any other way).&amp;nbsp; Solution?&amp;nbsp; Comments?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Apr 2013 18:31:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455333#M35789</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-04-17T18:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.AddLayer (SDE Feature Class)</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455334#M35790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think you want to use MakeFeatureLayer and add that as a layer object to your map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000006p000000" rel="nofollow" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000006p000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Apr 2013 21:05:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455334#M35790</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-04-17T21:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.AddLayer (SDE Feature Class)</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455335#M35791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think you want to use MakeFeatureLayer and add that as a layer object to your map.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000006p000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000006p000000&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ah.&amp;nbsp; Okay that works (sort of).&amp;nbsp; I get an error if I attempt to set the same fully qualified Feature Class name as it is in SDE.&amp;nbsp; This fails:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
if sdeFC == 'GIS.THE_FEATURE_CLASS_NAME':
&amp;nbsp;&amp;nbsp; sdeLyr = arcpy.mapping.Layer(sdeFC)
&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(sdeFC, "GIS.THE_FEATURE_CLASS_NAME")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;why would I want to add something to the map display that is NOT named what it is stored as?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also: Why is it "MakeFeatureLayer"?&amp;nbsp; This is not very descriptive of "Adding a Feature Class to the TOC"!&amp;nbsp; Lol...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:18:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455335#M35791</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T20:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.AddLayer (SDE Feature Class)</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455336#M35792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not sure why you would have an issue with using the qualified name. I don't get any error when using the same layer name as the feature class name. How are you creating your mxd and df objects?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 14:14:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455336#M35792</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-04-18T14:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.AddLayer (SDE Feature Class)</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455337#M35793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'm not sure why you would have an issue with using the qualified name. I don't get any error when using the same layer name as the feature class name. How are you creating your mxd and df objects?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def onRectangle(self, rectangle_geometry):
&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:18:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455337#M35793</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T20:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.AddLayer (SDE Feature Class)</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455338#M35794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That all seems fine, what is the error message you get?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 15:25:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455338#M35794</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-04-18T15:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.AddLayer (SDE Feature Class)</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455339#M35795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That all seems fine, what is the error message you get?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Didn't notice this until now, but arcgisscripting????&amp;nbsp; What?&amp;nbsp; That is very odd.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000733: Output Layer: Same as input C:\\Users\\me\\AppData\\Roaming\ESRI\\Desktop10.1\\ArcCatalog\\mysdeserver.sde\GIS.THE_FEATURE_CLASS_NAME&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (MakeFeatureLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From ArcGIS 10.1 Help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"000733 : &amp;lt;value&amp;gt;: Same as input &amp;lt;value&amp;gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Description&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The input and output have been given the same name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Solution&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To prevent overwriting your input during the operation, change the output name to be unique from the input."&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 18:41:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455339#M35795</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-04-18T18:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping.AddLayer (SDE Feature Class)</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455340#M35796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;** Changes applied and resolved **&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for your suggestions.&amp;nbsp; I wasn't completely sold on the idea of using the MakeFeatureLayer_management function to load the SDE Feature Class and I revisted my initial approach.&amp;nbsp; So, this actually did work at first ("sort of"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.mapping.AddLayer(df, theFC, "BOTTOM") 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that when it loaded into the TOC, it was named only with the first couple of characters of the full FC datasource. After thinking about it, I figured that maybe I could just simply rename it to the full name after it loads.&amp;nbsp; And that seems to work for my needs -- just reseting the .name property is fine:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

arcpy.env.workspace = "C:\\Users\\me\\AppData\\Roaming\ESRI\\Desktop10.1\\ArcCatalog\\mysdeserver.sde"
&amp;nbsp;&amp;nbsp;&amp;nbsp; sdelist = arcpy.ListFeatureClasses()
&amp;nbsp;&amp;nbsp;&amp;nbsp; for sdeFC in sdelist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## locate the desired fc and add it to the TOC
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if sdeFC == 'GIS.THE_FEATURE_CLASS_NAME':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sdeLyr = arcpy.mapping.Layer(sdeFC)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, sdeLyr, "BOTTOM")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## reset the fc's name after it is added to the TOC
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ListLayers(mxd)[0].name = "GIS.THE_FEATURE_CLASS_NAME"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC()

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:18:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-addlayer-sde-feature-class/m-p/455340#M35796</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T20:18:07Z</dc:date>
    </item>
  </channel>
</rss>

