<?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: Trying to do a selection, then export to PDF in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trying-to-do-a-selection-then-export-to-pdf/m-p/1203163#M65338</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/495426"&gt;@LeonConsus&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you open up your APRX and use the SelectByAttributes tool and add a query on the date field, check the SQL button (highlighted in yellow) and you will see the format that the SQL query needs to be in for a date field. Similar to below.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clubdebambos_0-1660641472246.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/48706i5F676C265BCE8141/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clubdebambos_0-1660641472246.png" alt="Clubdebambos_0-1660641472246.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Try set your sqlquery to&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sqlquery = "EditedDate &amp;gt;= timestamp '{0} 00:00:00'".format(date_time)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Aug 2022 09:23:56 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2022-08-16T09:23:56Z</dc:date>
    <item>
      <title>Trying to do a selection, then export to PDF</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-do-a-selection-then-export-to-pdf/m-p/1202003#M65337</link>
      <description>&lt;P&gt;Hello, I am a newbie ArcPy/Python user and am struggling with getting a mapseries to export with Python code.&amp;nbsp; I would like to have the code open the APRX, select from the index layer dates that have fallen in the last 2 days, then run the ms.exportToPDF on the selected.&amp;nbsp; I am using Python 3.9.11 and Arcpro 3.0&lt;/P&gt;&lt;P&gt;Here is the code I have (i have some print functions splattered throughout for data/variable checking):&lt;/P&gt;&lt;P&gt;import arcpy, os, sys&lt;BR /&gt;relpath = os.path.dirname(sys.argv[0])&lt;BR /&gt;print(relpath)&lt;/P&gt;&lt;P&gt;from datetime import date, timedelta&lt;BR /&gt;today = date.today()&lt;BR /&gt;print(today)&lt;BR /&gt;date2 = today - timedelta(days=2)&lt;BR /&gt;date_time = date2.strftime("%m/%d/%Y")&lt;BR /&gt;print(date2)&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject(r"W:\1.GIS\TEMP\AutoExports\PreSites_bu.aprx")&lt;BR /&gt;l = aprx.listLayouts()[0]&lt;BR /&gt;print ("Printing map series for layout: {}".format(l.name))&lt;/P&gt;&lt;P&gt;sqlquery = '"' + "EditDate" + '"' + " &amp;gt;= " + date_time&lt;/P&gt;&lt;P&gt;print(sqlquery)&lt;/P&gt;&lt;P&gt;if not l.mapSeries is None:&lt;BR /&gt;ms = l.mapSeries&lt;BR /&gt;if ms.enabled:&lt;BR /&gt;ms = l.mapSeries&lt;BR /&gt;indexLyr = ms.indexLayer&lt;BR /&gt;# arcpy.ca.SelectLayerByDateAndTime(indexLyr, "NEW_SELECTION", "SINGLE_TIME_FIELD", "EditDate", None, None, "DATE", "RECENCY", "2 Days")&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(indexLyr, "NEW_SELECTION", sqlquery)&lt;BR /&gt;ms.exportToPDF("W:\1.GIS\TEMP\Presite.pdf", "SELECTED")&lt;/P&gt;&lt;P&gt;I have tried using the REM'd out selection using recency, and also the active selection using the built "sqlquery".&amp;nbsp; I am getting this error:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "W:\BCHydro\1.GIS\TEMP\AutoExports\BCH_AutoExportPresite.py", line 30, in &amp;lt;module&amp;gt;&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(indexLyr, "NEW_SELECTION", sqlquery)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 10780, in SelectLayerByAttribute&lt;BR /&gt;raise e&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 10777, in SelectLayerByAttribute&lt;BR /&gt;retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), True)))&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;&lt;BR /&gt;return lambda *args: val(*gp_fixargs(args, True))&lt;BR /&gt;arcgisscripting.ExecuteError: ERROR 000358: Invalid expression&lt;BR /&gt;Failed to execute (SelectLayerByAttribute).&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 16:39:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-do-a-selection-then-export-to-pdf/m-p/1202003#M65337</guid>
      <dc:creator>LeonConsus</dc:creator>
      <dc:date>2022-08-11T16:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to do a selection, then export to PDF</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-do-a-selection-then-export-to-pdf/m-p/1203163#M65338</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/495426"&gt;@LeonConsus&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you open up your APRX and use the SelectByAttributes tool and add a query on the date field, check the SQL button (highlighted in yellow) and you will see the format that the SQL query needs to be in for a date field. Similar to below.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clubdebambos_0-1660641472246.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/48706i5F676C265BCE8141/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clubdebambos_0-1660641472246.png" alt="Clubdebambos_0-1660641472246.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Try set your sqlquery to&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sqlquery = "EditedDate &amp;gt;= timestamp '{0} 00:00:00'".format(date_time)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 09:23:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-do-a-selection-then-export-to-pdf/m-p/1203163#M65338</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2022-08-16T09:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to do a selection, then export to PDF</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-do-a-selection-then-export-to-pdf/m-p/1203315#M65339</link>
      <description>&lt;P&gt;Hi Clubdebambos!&lt;/P&gt;&lt;P&gt;That was a partial solution! And once I got that figured out, my other issues became more apparent and I was able to get a result!&amp;nbsp; Apparently Py does not like \1 in the directory structure either, so I corrected that and everything is now running!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 15:17:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-do-a-selection-then-export-to-pdf/m-p/1203315#M65339</guid>
      <dc:creator>LeonConsus</dc:creator>
      <dc:date>2022-08-16T15:17:19Z</dc:date>
    </item>
  </channel>
</rss>

