<?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: addlayer error!! in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762305#M58868</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what you are trying to do with this code. You loop through the layers in an MXD and check if the name equals "CNNDB". If that's the case you try to set a variable "addlayer". I don't think you should try to create a layer from a layer object. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next you try to add the layer to the dataframe (where the layer already exists), although the code does not run that far. And you intent to export the map to PDF. Is the loop through your layer really useful?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Aug 2014 21:33:40 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2014-08-06T21:33:40Z</dc:date>
    <item>
      <title>addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762304#M58867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am new in python but this script should be easy to process. Instead I get:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt; arcpy.mapping.AddLayer(myDF,addlayer) NameError: name 'addlayer' is not defined&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #303030;"&gt;Here is the script:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;thisMap = arcpy.mapping.MapDocument("CURRENT")&lt;/P&gt;&lt;P&gt;myDF = arcpy.mapping.ListDataFrames(thisMap)[0]&lt;/P&gt;&lt;P&gt;myLayers = arcpy.mapping.ListLayers(myDF)&lt;/P&gt;&lt;P&gt;for lyr in myLayers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "CNNDB":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addlayer = arcpy.mapping.Layer(lyr)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "got it"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayer(myDF,addlayer,"AUTO ARRANGE")&lt;/P&gt;&lt;P&gt;arcpy.CreateFolder_management(r"D:\GIS_data", "test")&lt;/P&gt;&lt;P&gt;arcpy.mapping.ExportToPDF(thisMap, r"D:\GIS_data\test\Project.pdf",300,"BEST",layers_attributes="LAYERS_AND_ATTRIBUTES")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Do you see any errors?&amp;nbsp; Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 20:58:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762304#M58867</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2014-08-06T20:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762305#M58868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what you are trying to do with this code. You loop through the layers in an MXD and check if the name equals "CNNDB". If that's the case you try to set a variable "addlayer". I don't think you should try to create a layer from a layer object. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next you try to add the layer to the dataframe (where the layer already exists), although the code does not run that far. And you intent to export the map to PDF. Is the loop through your layer really useful?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 21:33:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762305#M58868</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-06T21:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762306#M58869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, I modified my code....but I still getting an error.&lt;/P&gt;&lt;P&gt;What I am trying to do&amp;nbsp; is to loop through the layers of the current map and if a specific layer is found, then it will be copied onto a new map and then print the pdf of the new map.&lt;/P&gt;&lt;P&gt;Does it make sense?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;thisMap = arcpy.mapping.MapDocument("CURRENT")&lt;/P&gt;&lt;P&gt;myDF = arcpy.mapping.ListDataFrames(thisMap)[0]&lt;/P&gt;&lt;P&gt;arcpy.CreateFolder_management(r"D:\GIS_data", "test")&lt;/P&gt;&lt;P&gt;newmap = arcpy.mapping.MapDocument(r"D:\GIS_data\test\new.mxd")&lt;/P&gt;&lt;P&gt;newdf = arcpy.mapping.ListDataFrames(newmap)[0]&lt;/P&gt;&lt;P&gt;myLayers = arcpy.mapping.ListLayers(myDF)&lt;/P&gt;&lt;P&gt;for lyr in myLayers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "CNNDB":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addlayer = arcpy.mapping.Layer(lyr)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayer(newdf,addlayer,"AUTO ARRANGE")&lt;/P&gt;&lt;P&gt;arcpy.RefreshTOC&lt;/P&gt;&lt;P&gt;arcpy.RefreshActiveView&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.mapping.ExportToPDF(newmap, r"D:\GIS_data\test\Project.pdf",300,"BEST",layers_attributes="LAYERS_AND_ATTRIBUTES")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 21:41:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762306#M58869</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2014-08-06T21:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762307#M58870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see you are trying to create a new MXD through python by just accessing a non existing mxd file in a just created folder. That will not work. See the blog post below with an example of using ArcObjects inside Python for that purpose.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/1175"&gt;Create a new MXD through Python.&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is rather complex. You might want to consider creating an empty mxd file and copy that file for creating a new MXD.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 21:48:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762307#M58870</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-06T21:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762308#M58871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The addlayer variable is defined inside the for loop scope so it's not seen outside the loop, try to declare it before your loop then assign your matched layer to it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 22:10:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762308#M58871</guid>
      <dc:creator>9628807811</dc:creator>
      <dc:date>2014-08-06T22:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762309#M58872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry I am novice in Python. How do you declare a variable that if no layers are defined yet? Can I a declare without point at a layer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 22:30:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762309#M58872</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2014-08-06T22:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762310#M58873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/470459"&gt;@Ahmed&lt;/a&gt; that is not correct.&amp;nbsp; For loops do not have their own namespace, so the variable is in the local scope. Consider this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for i in range(2):
&amp;nbsp;&amp;nbsp;&amp;nbsp; loopvar = i * 2

print 'loopvar was defined in the loop and its value is {0}'.format(loopvar)



&lt;/PRE&gt;&lt;P&gt;The above code snippet works fine and prints:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;loopvar was defined in the loop and its value is 2



&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:24:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762310#M58873</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-12T08:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762311#M58874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, Luke, in my case&amp;nbsp; why the addlayer is undefined?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 01:04:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762311#M58874</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2014-08-08T01:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762312#M58875</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is this your full code? Do you have any try/except clauses in there that might be hiding earlier exceptions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't see how you would even get to `arcpy.mapping.AddLayer(newdf,addlayer,"AUTO ARRANGE")` as the `addlayer = arcpy.mapping.Layer(lyr)` would raise an exception anyway as `lyr` is a layer object, not a string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, the AddLayer method will raise an exception as "AUTO ARRANGE" is an invalid value, it must be one of ['TOP', 'AUTO_ARRANGE', 'BOTTOM'] Note the "_" underscore in "AUTO_ARRANGE".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is some code to get you started:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

thisMap = arcpy.mapping.MapDocument("CURRENT")
myDF = arcpy.mapping.ListDataFrames(thisMap)[0]
if not arcpy.Exists(r"D:\GIS_data\test"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFolder_management(r"D:\GIS_data", "test")
templatemap = arcpy.mapping.MapDocument(r"D:\GIS_data\template.mxd") #an existing empty mxd
templatedf = arcpy.mapping.ListDataFrames(templatemap)[0]

myLayers = arcpy.mapping.ListLayers(myDF,"CNNDB")
if myLayers:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(templatedf,myLayers[0],"AUTO_ARRANGE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; templatemap.saveACopy(r"D:\GIS_data\test\new.mxd")
&amp;nbsp;&amp;nbsp;&amp;nbsp; newmap=arcpy.mapping.MapDocument(r"D:\GIS_data\test\new.mxd")




&lt;/PRE&gt;&lt;P&gt;Notes:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;arcpy.mapping.MapDocument requires an existing MXD, it can not create a new one. Use an empty mxd as a template.&lt;/LI&gt;&lt;LI&gt;You can pass a layer name (or partial name + wildcard *) to the arcpy.mapping.ListLayers method.&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:24:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762312#M58875</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-12T08:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762313#M58876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanx Luke, for adding an example and the good explanation. This saves me some time &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 02:48:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762313#M58876</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-08T02:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762314#M58877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That was explained by Luke earlier. In case it finds the layer with the name you specify you try to pass a layer object to the arcpy.mapping.Layer() that expects a string...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 02:50:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762314#M58877</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-08T02:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762315#M58878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it possible that making a conventional toolbox (*.tbx) would have been a simpler approach?&amp;nbsp; I am just wondering why you have opted for this level of complexity when the tasks to perform seem relatively simple?&amp;nbsp; I am a curious as to what routes people take (ie ArcObjects, versus Addins vs tbx's versus standalone applications)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 13:29:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762315#M58878</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-08-08T13:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762316#M58879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand your point, but I have more than 500 shapefiles with their labels (contour field) to create and then export all of them to CAD. Even if I create a toolbox, it takes to much time to do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Clip Raster&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Create Contour&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Convert Labels to Annotations &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Export to CAD&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I thought by creating a tool that compile all this functions will saved me time and then share it to my colleagues.&lt;/P&gt;&lt;P&gt;And it was a good opportunity to see how python works for future tasks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 13:44:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762316#M58879</guid>
      <dc:creator>CARMETSandrine</dc:creator>
      <dc:date>2014-08-08T13:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762317#M58880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with Dan, what you describe can be done with a conventional toolbox that holds a simple python script to perform the analysis.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 13:46:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762317#M58880</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-08T13:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762318#M58881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It seems this is also suggested to you at your thread: &lt;A href="https://community.esri.com/thread/106182"&gt;How to use defined parameters in a tool ?&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;I think it's better to continue this discussion at your own thread&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 14:10:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762318#M58881</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-08T14:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762319#M58882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK , &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but for the"convert labels to annotation", is there a simple way&amp;nbsp; to ingrate it into a python script ? (because that's what makes me lose time, imagine I have more than 500 shapefiles to create and then convert all the labels to annotation to export all of them to CAD). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's why I was asking you to understand the "add layer" , to after activate the labels and then convert into annotation, all of this in the same python script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(Sorry if my english is not good, I'm french)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 14:12:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762319#M58882</guid>
      <dc:creator>CARMETSandrine</dc:creator>
      <dc:date>2014-08-08T14:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762320#M58883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK I think I just can not fully explain myself. &lt;/P&gt;&lt;P&gt;I will just continue to do it manually. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for every thing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 14:14:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762320#M58883</guid>
      <dc:creator>CARMETSandrine</dc:creator>
      <dc:date>2014-08-08T14:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762321#M58884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't worry about your English, it's fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The help page with examples for the tool you need can be found here:&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//007000000007000000"&gt;Tiled Labels To Annotation (Cartography)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 16:03:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762321#M58884</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-08T16:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762322#M58885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is untested and I have not fully vetted this, but I think you can try to reference the path name instead of trying to add the layer from another .mxd.&amp;nbsp; You can use arcpy.Describe to get the fully qualified path of the layer:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14075228292262533 jive_text_macro" jivemacro_uid="_14075228292262533" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;thisMap = arcpy.mapping.MapDocument("CURRENT")&lt;/P&gt;
&lt;P&gt;myDF = arcpy.mapping.ListDataFrames(thisMap)[0]&lt;/P&gt;
&lt;P&gt;arcpy.CreateFolder_management(r"D:\GIS_data", "test")&lt;/P&gt;
&lt;P&gt;newmap = arcpy.mapping.MapDocument(r"D:\GIS_data\test\new.mxd")&lt;/P&gt;
&lt;P&gt;newdf = arcpy.mapping.ListDataFrames(newmap)[0]&lt;/P&gt;
&lt;P&gt;myLayers = arcpy.mapping.ListLayers(myDF)&lt;/P&gt;
&lt;P&gt;for lyr in myLayers:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "CNNDB":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #set the path of the layer&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(lyr)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if hasattr(desc, "catalogPath"):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addlayer = desc.catalogPath&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#make a feaure layer to add to the new map&lt;/P&gt;
&lt;P&gt;arcpy.MakeFeatureLayer_management(addlayer, "layernametocallit")&lt;/P&gt;
&lt;P&gt;arcpy.mapping.AddLayer(newdf,"layernametocallit","AUTO ARRANGE")&lt;/P&gt;
&lt;P&gt;arcpy.RefreshTOC&lt;/P&gt;
&lt;P&gt;arcpy.RefreshActiveView&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 18:34:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762322#M58885</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-08-08T18:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: addlayer error!!</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762323#M58886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just whipped this together, and it doesn't fully meet your requirments but it does the first half of your task.&amp;nbsp; You will need to get the rest implemented (from converting to anno onwards).&amp;nbsp; Also, I ran into little problems that mostly got solved by NOT using .shp files and just setup File Geodatabases --- which is not a bad plan anyway.&amp;nbsp; Especially dealing with rasters for some reason, processing them outside of .gdb's is kwirky.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

ras = r'H:\Documents\inputraster.tif'
ras_ws = r'H:\Documents\rasters\clippedrasters.gdb'
ras_countours = r'H:\Documents\rasters\contours.gdb'
shp_ws = r'H:\Documents\shps'
arcpy.env.workspace = shp_ws
rascount = 1
for fc in arcpy.ListFeatureClasses():
&amp;nbsp;&amp;nbsp;&amp;nbsp; print fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; #create the clip rasters
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_management(ras,"#", ras_ws + "\\ras" + str(rascount),fc, "0", "ClippingGeometry")
&amp;nbsp;&amp;nbsp;&amp;nbsp; rascount = rascount + 1


#create the contours from the clipped rasters
### see if spatial analyst extension is available for use
availability = arcpy.CheckExtension("Spatial")
if availability == "Available":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CheckOutExtension("Spatial")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("SA Ext checked out")
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("%s extension is not available (%s)"%("Spatial Analyst Extension",availability))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("Please ask someone who has it checked out but not using to turn off the extension")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 


arcpy.env.workspace = ras_ws
contourcount = 1
for ras in arcpy.ListRasters():
&amp;nbsp;&amp;nbsp;&amp;nbsp; outname = ras_countours + "\\contour" + str(contourcount)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "ountname: " + outname
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.sa.Contour(ras, outname, 200, 0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; contourcount = contourcount + 1


#check the extension back in
arcpy.CheckInExtension("Spatial")

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:24:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/762323#M58886</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-12T08:24:26Z</dc:date>
    </item>
  </channel>
</rss>

