<?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: list map name that is reference to  a layout in arcgis pro project in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1249879#M66602</link>
    <description>&lt;P&gt;This is so weird.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It should work; I tested it a few times before posting, and I work in 2.9, so there isn't a huge difference.&lt;/P&gt;&lt;P&gt;However, when I try it today, I also have a runtime error.&lt;/P&gt;&lt;P&gt;Specifically, it looks like I can call methods on the map, but I can't call its properties; m.map.listLayers() works, but m.map.mapUnits does not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm going to submit a ticket for this and hopefully we'll get some resolution.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jan 2023 14:35:39 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2023-01-20T14:35:39Z</dc:date>
    <item>
      <title>list map name that is reference to  a layout in arcgis pro project</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1242471#M66310</link>
      <description>&lt;P&gt;I have a arcgis pro project that has 3 layouts each is references (linked or whatever the terminology may be) to one of the 3 maps that this project also have.&lt;/P&gt;&lt;P&gt;I tried to write code that uses a for loop to loop over the layout names and over the map name that associated to each layout. code below.&lt;/P&gt;&lt;P&gt;However i am able to get a list of all layouts and print that list of strings (keysList) but the map names that link to them is not returning. I read there a MapFrame element within a layout object that to my understanding contains the map name (among other elements, but I don't find how to call it and loop over it to access this attribute.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appriciates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
keysList = []
valuesList = []

aprx = arcpy.mp.ArcGISProject("CURRENT")

    for lyt in aprx.listLayouts():
        for m in lyt.listElements():
            keysList.append(lyt.name)
            valuesList.append(m.name)
print(keysList)
print(valuesList)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2022 19:15:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1242471#M66310</guid>
      <dc:creator>BarakGarty</dc:creator>
      <dc:date>2022-12-19T19:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: list map name that is reference to  a layout in arcgis pro project</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1242480#M66311</link>
      <description>&lt;P&gt;You were very close, just needed to filter the list.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
keysList = []
valuesList = []

aprx = arcpy.mp.ArcGISProject("CURRENT")

for lyt in aprx.listLayouts():
    #Filter down the list to only map frames
    for m in lyt.listElements("MAPFRAME_ELEMENT"):
    #You want the name of the map in map frame, not the map frame itself
        keysList.append(lyt.name)
        valuesList.append(m.map.name)
print(keysList)
print(valuesList)
'''Result'''
#['Layout', 'Layout']
#['Extent', 'Grey-scale']&lt;/LI-CODE&gt;&lt;P&gt;It might be cleaner to make a dictionary:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
mapDict= {}

aprx = arcpy.mp.ArcGISProject("CURRENT")
for lyt in aprx.listLayouts():
    #Filter down the list to only map frames
    for m in lyt.listElements("MAPFRAME_ELEMENT"):
        if lyt.name in mapDict:
            #You want the name of the map in map frame, not the map frame itself
            mapDict[lyt.name].append(m.map.name)
        else:
            mapDict[lyt.name]=[m.map.name]
print(mapDict)
'''Result'''
#{'Layout': ['Extent', 'Grey-scale']}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Helpful pages:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layout-class.htm" target="_blank" rel="noopener"&gt;Layout class&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/mapframe-class.htm" target="_blank" rel="noopener"&gt;Map Frame class&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2022 19:42:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1242480#M66311</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-12-19T19:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: list map name that is reference to  a layout in arcgis pro project</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1242495#M66313</link>
      <description>&lt;P&gt;Thank you Alfred. And you are right, I should have used a dictionary instead of two lists. Most appreciated your answer and feedback.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2022 20:06:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1242495#M66313</guid>
      <dc:creator>BarakGarty</dc:creator>
      <dc:date>2022-12-19T20:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: list map name that is reference to  a layout in arcgis pro project</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1249786#M66601</link>
      <description>&lt;P&gt;can this code work in 2.8? when I run the code m.map.name is not recognized.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 01:55:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1249786#M66601</guid>
      <dc:creator>chandlercoleman1</dc:creator>
      <dc:date>2023-01-20T01:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: list map name that is reference to  a layout in arcgis pro project</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1249879#M66602</link>
      <description>&lt;P&gt;This is so weird.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It should work; I tested it a few times before posting, and I work in 2.9, so there isn't a huge difference.&lt;/P&gt;&lt;P&gt;However, when I try it today, I also have a runtime error.&lt;/P&gt;&lt;P&gt;Specifically, it looks like I can call methods on the map, but I can't call its properties; m.map.listLayers() works, but m.map.mapUnits does not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm going to submit a ticket for this and hopefully we'll get some resolution.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 14:35:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1249879#M66602</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-01-20T14:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: list map name that is reference to  a layout in arcgis pro project</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1249898#M66603</link>
      <description>&lt;P&gt;Wait I think I figured it out.&lt;/P&gt;&lt;P&gt;I dug into my testing projects a little more to see where the error was occuring.&lt;/P&gt;&lt;P&gt;Specifically, it always occurred on the same Layout out of the four in the project.&lt;/P&gt;&lt;P&gt;I checked the layout, and guess what? The dataframe isn't referencing any map. Not sure when or how that happened, but here we are.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1674226949603.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60833i42DE13ED94FB5C43/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1674226949603.png" alt="AlfredBaldenweck_0-1674226949603.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_1-1674226972363.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60834i4842F23A4DFB4EF2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_1-1674226972363.png" alt="AlfredBaldenweck_1-1674226972363.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;For some reason, I couldn't get it to tell me straight out if it wasn't referencing anything.&lt;/P&gt;&lt;P&gt;So I ended up just making the whole thing a try/except.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
mapDict= {}
errorList = []
aprx = arcpy.mp.ArcGISProject("CURRENT")
for lyt in aprx.listLayouts():
    #Filter down the list to only map frames
    for m in lyt.listElements("MAPFRAME_ELEMENT"):
        try:
            if lyt.name in mapDict:
                #You want the name of the map in map frame, not the map frame itself
                mapDict[lyt.name].append(m.map.name)
            else:
                mapDict[lyt.name]=[m.map.name]
        except:
            errorList.append(lyt.name)
            
print(mapDict, "\n")

print("The following layouts had errors. \n" 
      "Check to see if their map frames are referencing a map.",
      "\n".join(errorList))


'''Results'''
#{'Layout': ['Data Call Wkbk'], 'Layout1': ['Georeferencing'], 'Layout2': ['Map1', 'Tracy_TallgrassMap']} 

#The following layouts had errors. 
#Check to see if their map frames are referencing a map.  Wind Project_2021_Fred&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 15:07:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1249898#M66603</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-01-20T15:07:23Z</dc:date>
    </item>
    <item>
      <title>RE: list map name that is reference to  a layout in arcgis pro project (Subscription Update)</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1249906#M66605</link>
      <description>Thanks for getting back to me. I appreciate your help. Let me know what you find out.&lt;BR /&gt;&lt;BR /&gt;Chandler Coleman&lt;BR /&gt;D 208 387 7138 M 208 949 9309&lt;BR /&gt;hdrinc.com/follow-us&amp;lt;&amp;gt;&lt;BR /&gt;&lt;BR /&gt;From: Esri Community&lt;BR /&gt;Sent: Friday, January 20, 2023 7:39 AM&lt;BR /&gt;To: Coleman, Chandler&lt;BR /&gt;Subject: Re: list map name that is reference to a layout in arcgis pro project (Subscription Update)&lt;BR /&gt;&lt;BR /&gt;CAUTION: [EXTERNAL] This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;*** DO NOT REPLY TO THIS E-MAIL ***&lt;BR /&gt;&lt;BR /&gt;To respond, use the hyperlinked Response Options at the bottom of your notification below OR visit the Esri Community post directly and reply from there.&lt;BR /&gt;&lt;BR /&gt;Hi chandlercoleman1,&lt;BR /&gt;&lt;BR /&gt;AlfredBaldenweck (Regular Contributor) posted a new reply in Python Questions&amp;lt;&amp;gt; on 01-20-2023 06:35 AM:&lt;BR /&gt;&lt;BR /&gt;________________________________&lt;BR /&gt;Re: list map name that is reference to a layout in arcgis pro project&amp;lt;&amp;gt;&lt;BR /&gt;&lt;BR /&gt;This is so weird. It should work; I tested it a few times before posting, and I work in 2.9, so there isn't a huge difference. However, when I try it today, I also have a runtime error. Specifically, it looks like I can call methods on the map, but I can't call its properties; m.map.listLayers() works, but m.map.mapUnits does not. I'm going to submit a ticket for this and hopefully we'll get some resolution.&lt;BR /&gt;&lt;BR /&gt;Reply | Give Kudos&amp;lt;&amp;gt;&lt;BR /&gt;&lt;BR /&gt;________________________________&lt;BR /&gt;&lt;BR /&gt;Esri Community sent this message to chandler.coleman@hdrinc.com.&lt;BR /&gt;You are receiving this email because a new message matches your subscription to a topic.&lt;BR /&gt;If you do not want to receive notification for this message, unsubscribe the topic&amp;lt;&amp;gt; or mute the message&amp;lt;&amp;gt;.&lt;BR /&gt;To manage your email notifications, go to your settings in the community&amp;lt;&amp;gt;.</description>
      <pubDate>Fri, 20 Jan 2023 15:24:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1249906#M66605</guid>
      <dc:creator>chandlercoleman1</dc:creator>
      <dc:date>2023-01-20T15:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: list map name that is reference to  a layout in arcgis pro project</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1250465#M66619</link>
      <description>&lt;P&gt;Thank works nicely.&amp;nbsp; Thankyou.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 17:51:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1250465#M66619</guid>
      <dc:creator>chandlercoleman1</dc:creator>
      <dc:date>2023-01-23T17:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: list map name that is reference to  a layout in arcgis pro project</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1252431#M66689</link>
      <description>&lt;P&gt;Hi again.&amp;nbsp; I was hoping you could help me understand how to use this code to pull the layers that are in the layout.&amp;nbsp; I am trying to pull this data into a CSV line by line:&lt;/P&gt;&lt;P&gt;layout name, map name, layer name, visible, etc&lt;/P&gt;&lt;P&gt;layout name, map name, layer name, visible, etc&lt;/P&gt;&lt;P&gt;I have some code that basically does this, but for an MDX.&amp;nbsp; I can't figure out how to make it do it for an APRX.&amp;nbsp; Any ideas would be appreciated.&amp;nbsp; thanks, chandler&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 17:15:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1252431#M66689</guid>
      <dc:creator>chandlercoleman1</dc:creator>
      <dc:date>2023-01-27T17:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: list map name that is reference to  a layout in arcgis pro project</title>
      <link>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1252470#M66691</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import csv
import pandas as pd

mapList= []
errorList = []
# Enter in the properties you care about
propList= ['brightness', 'visible', 'isBroken']
outCSV = r'W:\Downloads\testing.csv'

aprx = arcpy.mp.ArcGISProject("CURRENT")
for lyt in aprx.listLayouts():
    # Filter down the list to only map frames
    for m in lyt.listElements("MAPFRAME_ELEMENT"):
        try:
            for lay in m.map.listLayers(): 
                # Ignore group and base layers
                if lay.isGroupLayer is True:
                    continue
                if lay.isBasemapLayer is True:
                    continue
                tempList= [lyt.name, m.map.name, lay.name]
                for prop in propList:
                    #print(getattr(lay, prop,""))
                    tempList.extend([getattr(lay, prop,"")])
                mapList.append(tempList)    
                
        except:
            errorList.append(lyt.name)

with open(outCSV, 'w', newline='') as file:
        writer = csv.writer(file)
        heading = ["Layout", "Map", "Layer"]
        heading.extend(propList)
        writer.writerow(heading)
        writer.writerows(mapList)

#Delete duplicates. 
print("Deleting duplicates")
df = pd.read_csv(outCSV)
# This way drops any duplicate maps, leaving only the entries 
#    for the first layout in which they appear.
df= df.drop_duplicates(subset=heading[1:])
# This one just drops duplicates
#df= df.drop_duplicates()
df.to_csv(outCSV)

print("done")
if len(errorList)&amp;gt;0:
    print("The following layouts had errors. \n" 
          "Check to see if their map frames are referencing a map.",
          "\n".join(errorList))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This ought to do it.&lt;/P&gt;&lt;P&gt;It'll print out an excel sheet (file path in Line 9) containing the following columns: Layout, Map name, Layer name, and then whatever&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm" target="_blank" rel="noopener"&gt; properties&lt;/A&gt; you want, as entered into propList (Line 8 )(don't worry about the name, that goes in by default).&lt;/P&gt;&lt;P&gt;The end result looks like this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1674845187532.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61488i685C0F95E20BE77B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1674845187532.png" alt="AlfredBaldenweck_0-1674845187532.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As presented right now, it also gets rid of duplicate entries for maps. To ignore this and list all maps, regardless of how many times they appear, just comment out Line 43 and un-comment Line 45.&lt;/P&gt;&lt;P&gt;If you're interested in just one layout, you can filter it down in Line 12, e.g. &lt;STRONG&gt;&lt;EM&gt;aprx.listLayouts('Layout 1')&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 18:56:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-map-name-that-is-reference-to-a-layout-in/m-p/1252470#M66691</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-01-27T18:56:14Z</dc:date>
    </item>
  </channel>
</rss>

