<?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 Why can't I use a variable to specify a page name field? in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/why-can-t-i-use-a-variable-to-specify-a-page-name/m-p/1557078#M89964</link>
    <description>&lt;P&gt;I have the below code to export a map series into multiple PNGs. On line 13, I'm getting an error "AttributeError: 'pageRow' object has no attribute 'page_name_field'"&lt;/P&gt;&lt;P&gt;When I run the script, I input the name of the field as a string, in this case "PageNumber." However, when I run this by just putting "pageName = ms.pageRow.PageNumber" it runs correctly. Is there a reason I can't use a variable in this case?&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
import os
import sys
aprx = arcpy.mp.ArcGISProject("CURRENT")
layout_input = arcpy.GetParameterAsText(0)
resoultion_input = int(arcpy.GetParameterAsText(1))
output_folder = arcpy.GetParameterAsText(2)
page_name_field = arcpy.GetParameterAsText(3)
lyt = aprx.listLayouts(layout_input)[0]
ms = lyt.mapSeries
for pageNum in range(1,ms.pageCount +1):
    ms.currentPageNumber = pageNum
    pageName = ms.pageRow.page_name_field
    arcpy.AddMessage(f"Exporting {pageName}")
    lyt.exportToPNG((os.path.join(output_folder, f'Ex2_{pageName}.png')), resolution = resoultion_input)&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>Sat, 09 Nov 2024 00:44:34 GMT</pubDate>
    <dc:creator>rescobar</dc:creator>
    <dc:date>2024-11-09T00:44:34Z</dc:date>
    <item>
      <title>Why can't I use a variable to specify a page name field?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/why-can-t-i-use-a-variable-to-specify-a-page-name/m-p/1557078#M89964</link>
      <description>&lt;P&gt;I have the below code to export a map series into multiple PNGs. On line 13, I'm getting an error "AttributeError: 'pageRow' object has no attribute 'page_name_field'"&lt;/P&gt;&lt;P&gt;When I run the script, I input the name of the field as a string, in this case "PageNumber." However, when I run this by just putting "pageName = ms.pageRow.PageNumber" it runs correctly. Is there a reason I can't use a variable in this case?&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
import os
import sys
aprx = arcpy.mp.ArcGISProject("CURRENT")
layout_input = arcpy.GetParameterAsText(0)
resoultion_input = int(arcpy.GetParameterAsText(1))
output_folder = arcpy.GetParameterAsText(2)
page_name_field = arcpy.GetParameterAsText(3)
lyt = aprx.listLayouts(layout_input)[0]
ms = lyt.mapSeries
for pageNum in range(1,ms.pageCount +1):
    ms.currentPageNumber = pageNum
    pageName = ms.pageRow.page_name_field
    arcpy.AddMessage(f"Exporting {pageName}")
    lyt.exportToPNG((os.path.join(output_folder, f'Ex2_{pageName}.png')), resolution = resoultion_input)&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>Sat, 09 Nov 2024 00:44:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/why-can-t-i-use-a-variable-to-specify-a-page-name/m-p/1557078#M89964</guid>
      <dc:creator>rescobar</dc:creator>
      <dc:date>2024-11-09T00:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't I use a variable to specify a page name field?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/why-can-t-i-use-a-variable-to-specify-a-page-name/m-p/1557091#M89966</link>
      <description>&lt;P&gt;Because when you are trying to use&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ms.pageRow.page_name_field&lt;/FONT&gt;, python is looking for an attribute in the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;pageRow&lt;/FONT&gt; object literally called&amp;nbsp;&lt;FONT face="courier new,courier"&gt;page_name_field&lt;/FONT&gt; which does not exist.&amp;nbsp; You can use python's &lt;FONT face="courier new,courier"&gt;getattr()&lt;/FONT&gt; function to dynamically evaluate the variable. E.g.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;pageName = getattr(ms.pageRow, page_name_field)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 05:28:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/why-can-t-i-use-a-variable-to-specify-a-page-name/m-p/1557091#M89966</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2024-11-09T05:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Why can't I use a variable to specify a page name field?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/why-can-t-i-use-a-variable-to-specify-a-page-name/m-p/1557611#M90054</link>
      <description>&lt;P&gt;Thanks, this worked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 16:39:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/why-can-t-i-use-a-variable-to-specify-a-page-name/m-p/1557611#M90054</guid>
      <dc:creator>rescobar</dc:creator>
      <dc:date>2024-11-12T16:39:09Z</dc:date>
    </item>
  </channel>
</rss>

