<?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 How to work with map layers in in-memory ArcGIS Pro project created with ConvertWebMapToArcGISProject? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-work-with-map-layers-in-in-memory-arcgis/m-p/297491#M22985</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;TLDR&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;- Since there may be a lot to unpack here, let me start with a nutshell version of what I'm asking:&lt;/P&gt;&lt;OL style="padding: 0px 0px 0px 30px;"&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What's the&amp;nbsp;suggested use of and what are the limitations of web layers and staged vector layers in a aprx-map created from JSON?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What governs whether a property is supported by a specific layer/layer of either type?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What could be behind perfectly good "staged service layers" not exporting to PDF?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;H3 style="font-weight: bold; font-size: 18px;" id="toc-hId-1456591995"&gt;Long Version :&lt;/H3&gt;&lt;P&gt;I can't seem to figure out how to work with the in-memory ArcGISProcect that is created using 'ConvertWebMapToArcGISProject'. It's straight forward if all you want to do is print what's in a web map or even use a Layout. Beyond that, it blows my mind.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Background&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;- I've&amp;nbsp;managed to capture webmap as JSON in&amp;nbsp;a custom WAB widget and passed that into a custom Python GP service. But working with the map here, I currently run into issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When using 'ConvertWebMapToArcGISProject' with a .pagx file,...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;result &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;ConvertWebMapToArcGISProject&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;Web_Map_as_JSON_new&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt;templatePagx&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt;mapframe_name&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;
aprx &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; result&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;ArcGISProject
myMap &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; aprx&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;listMaps&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #669900;"&gt;'Web Map'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #990000;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;]&lt;/SPAN&gt;‍‍‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;you end up with all one set of layers derived from the web map and one set of layers ESRI refers to as "&lt;SPAN style="color: #4c4c4c; background-color: #ffffff;"&gt;staged vector layers" - those layers&amp;nbsp;&lt;/SPAN&gt;that are referenced in your Layout. That was a surprise at first but is actually included in the documentation (&lt;A href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/convertwebmaptoarcgisproject.htm" style="color: #2989c5; text-decoration: none;" rel="nofollow noopener noreferrer" target="_blank"&gt;Example 3 on this page&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;In my case, the layout comes from a Pro project and references the same map that was used to publish the service feeding the web map. So there is a one-to-one match between web layers. Make sense?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next, since I now have a corresponding layer in my Pro Layout for each layer in the webmap, I remove all the webmap layers. I am not entirely sure what the role/advantage/use of each of the two types of layers here is, or why I can't or shouldn't work with the web layers. That's part of my question. But I proceed to remove&amp;nbsp;them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="" style="color: #0077aa;"&gt;in&lt;/SPAN&gt; myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="" style="color: #0077aa;"&gt;if&lt;/SPAN&gt; lyr&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;isWebLayer&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
        myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Now when I iterate over all my layers, and check visibility, only those that were turned on in the Pro project's map and the state of the Layout when it was used to file are turned on. Upto this point - from web app =&amp;gt; Json =&amp;gt; to Python GP logic - no issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want to do next&amp;nbsp;is: dump some layers in a list, turn them all off and then iterate over the list, turning them on as needed, each time creating a PDF. These layers&amp;nbsp;all belong to the same GroupLayer in Pro and the map service. But I want to create a separate PDF for each.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# First turn them all off&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; myListOfLayers&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;visible &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# Then turn them on one by one&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; range&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;myListOfLayers&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;
   myListOfLayers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;visible &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;
   
   &lt;SPAN class="comment token"&gt;# create my PDF&lt;/SPAN&gt;

   myListOfLayers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;visible &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&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;/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;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;As I do so, I can check that the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;right&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;layers are turned to visible and others aren't. Runs great.&amp;nbsp;The following puts out one PDF for each layer in my list&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;layout&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;exportToPDF&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;layerPDF&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; resolution &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; &lt;SPAN class="" style="color: #990000;"&gt;300&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;The layout of the file that is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;generated&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is the desired one from the Pro project. The legend looks correct and shows all the layers. But the&amp;nbsp;map is blank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These same layers (based on layer.dataSource and layer.connectionProperties are what they should be based on what's in my Pro project. When I run the same code against my Pro project (referencing an APRX file rather than creating one from JSON) using the familiar syntax...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;aprx &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;&amp;lt;&lt;/SPAN&gt;path_to_APRX_File&lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it works flawlessly, generates a series of PDF pages and later&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;bundles&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;them into one file. So what am I doing wrong with APRX created from webmap? Why are my maps blank?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Like I said above, I'm not sure why I should be working with the "stages service layers" that 'ConvertWebMapToArcGISProject' creates for you. If I try to use the weblayers instead, this is what happens.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="" style="color: #0077aa;"&gt;in&lt;/SPAN&gt; myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="" style="color: #0077aa;"&gt;if&lt;/SPAN&gt; &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;not&lt;/SPAN&gt; lyr&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;isWebLayer&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
        myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You'd think this should work (in light of the fact I haven't found any documentation explaining why&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;it&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;shouldn't). But:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&amp;lt;ipython-input-206-cc7d5dde5fc1&amp;gt; in &amp;lt;module&amp;gt;
      1 for layer in myMap.listLayers():
      2     if not layer.isWebLayer:
----&amp;gt; 3         myMap.removeLayer(layer)
      4 

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py in removeLayer(self, remove_layer)
   1801              remove_layer(Layer):
   1802            A reference to a Layer object representing the layer to be removed."""
-&amp;gt; 1803         return convertArcObjectToPythonObject(self._arc_object.removeLayer(*gp_fixargs((remove_layer,), True)))
   1804 
   1805     def removeTable(self, remove_table):
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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;/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;So&amp;nbsp;removing staged service layers&amp;nbsp;appears to be behaving quite differently&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;from removing&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;webmap layers. It bombs at trying to remove a layer once the parent GroupLayer has been removed. Instead&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I can&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;do this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;for&lt;/SPAN&gt; layer &lt;SPAN class="" style="color: #0077aa;"&gt;in&lt;/SPAN&gt; myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="" style="color: #0077aa;"&gt;if&lt;/SPAN&gt; &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;not&lt;/SPAN&gt; layer&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;isWebLayer&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="" style="color: #0077aa;"&gt;try&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
            myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;layer&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;
        &lt;SPAN class="" style="color: #0077aa;"&gt;except&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
            &lt;SPAN class="" style="color: #0077aa;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #669900;"&gt;"can't remove this one... "&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;This removes all&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"staged vector layers" and leaves you with only&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;web layers. It appears that web layers&amp;nbsp;don't know about GroupLayers but "staged service layers". Hmm. Why?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now, I try the same as before, I iterate over my list of layers to create PDFs. This is what happens.&amp;nbsp;The code fails after 3 loops with this error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;During handling of the above exception, another exception occurred:

NameError                                 Traceback (most recent call last)
&amp;lt;ipython-input-308-9a972bcf26b6&amp;gt; in &amp;lt;module&amp;gt;
      2     
      3 
----&amp;gt; 4     myListOfLayers&lt;I&gt;.visible = True
      5     
      6     

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py in _set(self, val)
    113                     gp.getIDMessage(89013,
    114                         "The attribute %r is not supported on this instance of %s.") %
--&amp;gt; 115                     (attr_name, self.__class__.__name__))
    116     def _del(self, val):
    117         return delattr(self._arc_object, val)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/CODE&gt;&lt;I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It runs through two layers in the list with no problem and then fails&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;on an almost identical layer #3. Oh my!&amp;nbsp;&amp;nbsp;The first three PDF's&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;that are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;created look good&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as far as the map goes. But I've lost my legend. Apparently removing the Layout referenced layers has wiped out the legend. So&amp;nbsp;that suggests I need to work with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;staged vector layers&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;after all. But there is no obvious reason that layer #3 is any different from 1 or 2 except maybe in def queries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL style="padding: 0px 0px 0px 30px;"&gt;&lt;LI style="margin: 0.2em 0px;"&gt;So what would prevent me from turning off a particular layer or&amp;nbsp;why would a particular layer not support "VISIBLE".&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What should I be using web layers for versus "staged services layers"?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What would keep the "staged service layers" from plotting in the PDF when the same code works inside a Pro project?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Does layer visibility (turning on/off) depend on any other layer properties? What am I looking for&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;when comparing as to why one turns of and the other doesn't?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Are there any known limitations to this when using GroupLayers? I've had better luck on another project when not using them. But I don't always have full control over the services I consume.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't expect anyone to have answers for all of these. But I'll take any answers or suggestions. This has been very frustrating. If there is better documentation, please point me to it and I will absorb every line.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 14:16:39 GMT</pubDate>
    <dc:creator>Arne_Gelfert</dc:creator>
    <dc:date>2021-12-11T14:16:39Z</dc:date>
    <item>
      <title>How to work with map layers in in-memory ArcGIS Pro project created with ConvertWebMapToArcGISProject?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-work-with-map-layers-in-in-memory-arcgis/m-p/297491#M22985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;TLDR&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;- Since there may be a lot to unpack here, let me start with a nutshell version of what I'm asking:&lt;/P&gt;&lt;OL style="padding: 0px 0px 0px 30px;"&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What's the&amp;nbsp;suggested use of and what are the limitations of web layers and staged vector layers in a aprx-map created from JSON?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What governs whether a property is supported by a specific layer/layer of either type?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What could be behind perfectly good "staged service layers" not exporting to PDF?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;H3 style="font-weight: bold; font-size: 18px;" id="toc-hId-1456591995"&gt;Long Version :&lt;/H3&gt;&lt;P&gt;I can't seem to figure out how to work with the in-memory ArcGISProcect that is created using 'ConvertWebMapToArcGISProject'. It's straight forward if all you want to do is print what's in a web map or even use a Layout. Beyond that, it blows my mind.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Background&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;- I've&amp;nbsp;managed to capture webmap as JSON in&amp;nbsp;a custom WAB widget and passed that into a custom Python GP service. But working with the map here, I currently run into issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When using 'ConvertWebMapToArcGISProject' with a .pagx file,...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;result &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;ConvertWebMapToArcGISProject&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;Web_Map_as_JSON_new&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt;templatePagx&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt;mapframe_name&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;
aprx &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; result&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;ArcGISProject
myMap &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; aprx&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;listMaps&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #669900;"&gt;'Web Map'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #990000;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;]&lt;/SPAN&gt;‍‍‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;you end up with all one set of layers derived from the web map and one set of layers ESRI refers to as "&lt;SPAN style="color: #4c4c4c; background-color: #ffffff;"&gt;staged vector layers" - those layers&amp;nbsp;&lt;/SPAN&gt;that are referenced in your Layout. That was a surprise at first but is actually included in the documentation (&lt;A href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/convertwebmaptoarcgisproject.htm" style="color: #2989c5; text-decoration: none;" rel="nofollow noopener noreferrer" target="_blank"&gt;Example 3 on this page&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;In my case, the layout comes from a Pro project and references the same map that was used to publish the service feeding the web map. So there is a one-to-one match between web layers. Make sense?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next, since I now have a corresponding layer in my Pro Layout for each layer in the webmap, I remove all the webmap layers. I am not entirely sure what the role/advantage/use of each of the two types of layers here is, or why I can't or shouldn't work with the web layers. That's part of my question. But I proceed to remove&amp;nbsp;them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="" style="color: #0077aa;"&gt;in&lt;/SPAN&gt; myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="" style="color: #0077aa;"&gt;if&lt;/SPAN&gt; lyr&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;isWebLayer&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
        myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Now when I iterate over all my layers, and check visibility, only those that were turned on in the Pro project's map and the state of the Layout when it was used to file are turned on. Upto this point - from web app =&amp;gt; Json =&amp;gt; to Python GP logic - no issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want to do next&amp;nbsp;is: dump some layers in a list, turn them all off and then iterate over the list, turning them on as needed, each time creating a PDF. These layers&amp;nbsp;all belong to the same GroupLayer in Pro and the map service. But I want to create a separate PDF for each.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# First turn them all off&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; myListOfLayers&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;visible &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# Then turn them on one by one&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; range&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;myListOfLayers&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;
   myListOfLayers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;visible &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;
   
   &lt;SPAN class="comment token"&gt;# create my PDF&lt;/SPAN&gt;

   myListOfLayers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;visible &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&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;/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;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;As I do so, I can check that the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;right&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;layers are turned to visible and others aren't. Runs great.&amp;nbsp;The following puts out one PDF for each layer in my list&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;layout&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;exportToPDF&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;layerPDF&lt;SPAN class="" style="color: #999999;"&gt;,&lt;/SPAN&gt; resolution &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; &lt;SPAN class="" style="color: #990000;"&gt;300&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;The layout of the file that is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;generated&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is the desired one from the Pro project. The legend looks correct and shows all the layers. But the&amp;nbsp;map is blank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These same layers (based on layer.dataSource and layer.connectionProperties are what they should be based on what's in my Pro project. When I run the same code against my Pro project (referencing an APRX file rather than creating one from JSON) using the familiar syntax...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;aprx &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;&amp;lt;&lt;/SPAN&gt;path_to_APRX_File&lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it works flawlessly, generates a series of PDF pages and later&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;bundles&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;them into one file. So what am I doing wrong with APRX created from webmap? Why are my maps blank?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Like I said above, I'm not sure why I should be working with the "stages service layers" that 'ConvertWebMapToArcGISProject' creates for you. If I try to use the weblayers instead, this is what happens.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="" style="color: #0077aa;"&gt;in&lt;/SPAN&gt; myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="" style="color: #0077aa;"&gt;if&lt;/SPAN&gt; &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;not&lt;/SPAN&gt; lyr&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;isWebLayer&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
        myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You'd think this should work (in light of the fact I haven't found any documentation explaining why&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;it&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;shouldn't). But:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&amp;lt;ipython-input-206-cc7d5dde5fc1&amp;gt; in &amp;lt;module&amp;gt;
      1 for layer in myMap.listLayers():
      2     if not layer.isWebLayer:
----&amp;gt; 3         myMap.removeLayer(layer)
      4 

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py in removeLayer(self, remove_layer)
   1801              remove_layer(Layer):
   1802            A reference to a Layer object representing the layer to be removed."""
-&amp;gt; 1803         return convertArcObjectToPythonObject(self._arc_object.removeLayer(*gp_fixargs((remove_layer,), True)))
   1804 
   1805     def removeTable(self, remove_table):
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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;/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;So&amp;nbsp;removing staged service layers&amp;nbsp;appears to be behaving quite differently&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;from removing&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;webmap layers. It bombs at trying to remove a layer once the parent GroupLayer has been removed. Instead&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;I can&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;do this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: #0077aa;"&gt;for&lt;/SPAN&gt; layer &lt;SPAN class="" style="color: #0077aa;"&gt;in&lt;/SPAN&gt; myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="" style="color: #0077aa;"&gt;if&lt;/SPAN&gt; &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5);"&gt;not&lt;/SPAN&gt; layer&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;isWebLayer&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="" style="color: #0077aa;"&gt;try&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
            myMap&lt;SPAN class="" style="color: #999999;"&gt;.&lt;/SPAN&gt;removeLayer&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;layer&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;
        &lt;SPAN class="" style="color: #0077aa;"&gt;except&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;:&lt;/SPAN&gt;
            &lt;SPAN class="" style="color: #0077aa;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #669900;"&gt;"can't remove this one... "&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999;"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍&lt;SPAN class="" style="border-right: 1px solid #999999; padding-top: 1em;"&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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;This removes all&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"staged vector layers" and leaves you with only&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;web layers. It appears that web layers&amp;nbsp;don't know about GroupLayers but "staged service layers". Hmm. Why?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now, I try the same as before, I iterate over my list of layers to create PDFs. This is what happens.&amp;nbsp;The code fails after 3 loops with this error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;During handling of the above exception, another exception occurred:

NameError                                 Traceback (most recent call last)
&amp;lt;ipython-input-308-9a972bcf26b6&amp;gt; in &amp;lt;module&amp;gt;
      2     
      3 
----&amp;gt; 4     myListOfLayers&lt;I&gt;.visible = True
      5     
      6     

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py in _set(self, val)
    113                     gp.getIDMessage(89013,
    114                         "The attribute %r is not supported on this instance of %s.") %
--&amp;gt; 115                     (attr_name, self.__class__.__name__))
    116     def _del(self, val):
    117         return delattr(self._arc_object, val)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/CODE&gt;&lt;I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It runs through two layers in the list with no problem and then fails&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;on an almost identical layer #3. Oh my!&amp;nbsp;&amp;nbsp;The first three PDF's&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;that are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;created look good&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as far as the map goes. But I've lost my legend. Apparently removing the Layout referenced layers has wiped out the legend. So&amp;nbsp;that suggests I need to work with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;staged vector layers&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;after all. But there is no obvious reason that layer #3 is any different from 1 or 2 except maybe in def queries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL style="padding: 0px 0px 0px 30px;"&gt;&lt;LI style="margin: 0.2em 0px;"&gt;So what would prevent me from turning off a particular layer or&amp;nbsp;why would a particular layer not support "VISIBLE".&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What should I be using web layers for versus "staged services layers"?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;What would keep the "staged service layers" from plotting in the PDF when the same code works inside a Pro project?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Does layer visibility (turning on/off) depend on any other layer properties? What am I looking for&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;when comparing as to why one turns of and the other doesn't?&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Are there any known limitations to this when using GroupLayers? I've had better luck on another project when not using them. But I don't always have full control over the services I consume.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't expect anyone to have answers for all of these. But I'll take any answers or suggestions. This has been very frustrating. If there is better documentation, please point me to it and I will absorb every line.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:16:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-work-with-map-layers-in-in-memory-arcgis/m-p/297491#M22985</guid>
      <dc:creator>Arne_Gelfert</dc:creator>
      <dc:date>2021-12-11T14:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to work with map layers in in-memory ArcGIS Pro project created with ConvertWebMapToArcGISProject?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-work-with-map-layers-in-in-memory-arcgis/m-p/297492#M22986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wow - this one has been a beating. Finally got it to work though. Lessons learned are:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Those web layers behave differently from the staged service layers. They also begin their lives in the new aprx map with different settings, e.g. visibility. They do not work the&amp;nbsp;same for Group Layers. Whether that's by design, I don't know. I finally did get it to work by removing off web layers.&lt;/LI&gt;&lt;LI&gt;What did the trick for me was when I realized the following lines&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;legend_element&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;syncLayerVisibility &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;
legend_element&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;syncLayerOrder &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&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;/CODE&gt;&lt;/PRE&gt;&lt;P style="padding-left: 30px;"&gt;don't mean "keep map and legend synch'd" but they mean "synch map and legend now and only once". So when you're iterating over a list of layers, turning various things on/off, you always have to invoke those lines again to make sure legend and map show the same things.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Now,&amp;nbsp;I'm just running into another ESRI Bug because wanting to turn off Group Layer names in a Pro layout's legend only works for the top entry.&amp;nbsp;&lt;A class="link-titled" href="https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEyODY4OA==" title="https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEyODY4OA==" rel="nofollow noopener noreferrer" target="_blank"&gt;BUG-000128688: The Group layer name option in the Format Legend Ite..&lt;/A&gt;&amp;nbsp;So stupid! Looks like maybe it hasn't been fixed in 2.6. None of the work-arounds suggested &lt;A _jive_internal="true" href="https://community.esri.com/thread/247992-locked-legend-items" target="_blank"&gt;here&lt;/A&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well at least I get my PDF maps now and have the ability to rename layers in the legend. Nice side-effect has been that I've dug around the world of CIM as I've been exploring and will be using that a lot more going forward.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:16:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-work-with-map-layers-in-in-memory-arcgis/m-p/297492#M22986</guid>
      <dc:creator>Arne_Gelfert</dc:creator>
      <dc:date>2021-12-11T14:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to work with map layers in in-memory ArcGIS Pro project created with ConvertWebMapToArcGISProject?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-work-with-map-layers-in-in-memory-arcgis/m-p/297493#M22987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Turns out hiding the Group Layer labels in the legend can be accomplished by setting them to an empty string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Well... that was easy.&amp;nbsp;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Oct 2020 22:02:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-work-with-map-layers-in-in-memory-arcgis/m-p/297493#M22987</guid>
      <dc:creator>Arne_Gelfert</dc:creator>
      <dc:date>2020-10-02T22:02:50Z</dc:date>
    </item>
  </channel>
</rss>

