<?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 Assertion error on ExportToPDF function. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605010#M47266</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I'm new to ArcMapping with Python. For my first task I decided to do a batch export of maps. My code is simple but I get an error that has me stumped. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os
inpath="C:\\GIS\\MXD_dir\\"
outpath="C:\\Out_map_dir\\"
dirList = os.listdir(inpath)

arcpy.OverWriteOutput = 1

for item in dirList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print inpath + item
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(inpath + item, outpath + item[:-4] + ".pdf" )
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToJPEG(inpath + item, outpath + item[:-4] +".jpg" )

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is my error...&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Traceback (most recent call last):
&amp;nbsp; File "C:\GIS\Scripts\pdf_export.py", line 9, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(inpath + item, outpath + item[:-4] + ".pdf" )
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 179, in fn_
&amp;nbsp;&amp;nbsp;&amp;nbsp; return fn(*args, **kw)
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\mapping.py", line 790, in ExportToPDF
&amp;nbsp;&amp;nbsp;&amp;nbsp; assert isinstance(map_document, MapDocument)
AssertionError&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help or insight would be appreciated. Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 15 Dec 2011 16:25:13 GMT</pubDate>
    <dc:creator>JasonTaylor</dc:creator>
    <dc:date>2011-12-15T16:25:13Z</dc:date>
    <item>
      <title>Assertion error on ExportToPDF function.</title>
      <link>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605010#M47266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, I'm new to ArcMapping with Python. For my first task I decided to do a batch export of maps. My code is simple but I get an error that has me stumped. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os
inpath="C:\\GIS\\MXD_dir\\"
outpath="C:\\Out_map_dir\\"
dirList = os.listdir(inpath)

arcpy.OverWriteOutput = 1

for item in dirList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print inpath + item
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(inpath + item, outpath + item[:-4] + ".pdf" )
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToJPEG(inpath + item, outpath + item[:-4] +".jpg" )

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is my error...&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Traceback (most recent call last):
&amp;nbsp; File "C:\GIS\Scripts\pdf_export.py", line 9, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(inpath + item, outpath + item[:-4] + ".pdf" )
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 179, in fn_
&amp;nbsp;&amp;nbsp;&amp;nbsp; return fn(*args, **kw)
&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\mapping.py", line 790, in ExportToPDF
&amp;nbsp;&amp;nbsp;&amp;nbsp; assert isinstance(map_document, MapDocument)
AssertionError&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help or insight would be appreciated. Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 16:25:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605010#M47266</guid>
      <dc:creator>JasonTaylor</dc:creator>
      <dc:date>2011-12-15T16:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Assertion error on ExportToPDF function.</title>
      <link>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605011#M47267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You might be having issue joining your path name to your file name. try something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.mapping.ExportToPDF(inpath + "\\" + item, outpath + "\\" + item[:-4] + ".pdf" )
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:56:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605011#M47267</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-12-12T01:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Assertion error on ExportToPDF function.</title>
      <link>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605012#M47268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I thought I took care of that in the when I set the path in in the path variable by adding "\\" there. I tried it any way and got the same error. Thanks though.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 17:00:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605012#M47268</guid>
      <dc:creator>JasonTaylor</dc:creator>
      <dc:date>2011-12-15T17:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Assertion error on ExportToPDF function.</title>
      <link>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605013#M47269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a feeling it has something to do with the way your are looping through your mxd's using dirList = os.listdir(inpath).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a similar code to flip through a directory of .mxd's and exports to pdf. Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, glob, os, sys

inpath = r"C:\GIS\MXD_dir\"
outpath=r"C:\Out_map_dir\"

for filename in glob.glob(os.path.join(inPath, "*.mxd")):

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullpath = os.path.join(inPath, filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(filename)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullpath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, filename2 = os.path.split(fullpath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shortname, extension = os.path.splitext(filename2)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, outpath + "\\" + shortname, "PAGE_LAYOUT")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del shortname
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del basename
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del filename2
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del extension
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del filename
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:56:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605013#M47269</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-12-12T01:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Assertion error on ExportToPDF function.</title>
      <link>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605014#M47270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, this works great. Thanks for helping me through this. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to research more about glob and the os.path functions, because I'm not sure why it won't work. Your definitely right though, there is a difference.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for the help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 22:16:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605014#M47270</guid>
      <dc:creator>JasonTaylor</dc:creator>
      <dc:date>2011-12-15T22:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Assertion error on ExportToPDF function.</title>
      <link>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605015#M47271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It wasn't working because the first parameter in your original ExportToPDF and ExportToJPG functions were using an MXD path, not an MXD reference.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Dec 2011 13:21:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605015#M47271</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2011-12-16T13:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Assertion error on ExportToPDF function.</title>
      <link>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605016#M47272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ah, I see. This was the crucial line I was missing&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument(filename)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Adding it, my code works great!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
inpath="C:\\GIS\\MXD_dir\\"
outpath="C:\\Out_map_dir\\"
dirList = os.listdir(inpath)

for item in dirList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;mxd = arcpy.mapping.MapDocument(inpath + item)&lt;/STRONG&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(inpath + item, outpath + item[:-4])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToJPEG(inpath + item, outpath + item[:-4])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also removed the the output extensions, not sure if that matters though. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:56:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605016#M47272</guid>
      <dc:creator>JasonTaylor</dc:creator>
      <dc:date>2021-12-12T01:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Assertion error on ExportToPDF function.</title>
      <link>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605017#M47273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you!&amp;nbsp; I was missing&amp;nbsp; mxd = arcpy.mapping.MapDocument(mxdname), and this line before using arcpy.mapping.ExportToPDF&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fixed the problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 13:39:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assertion-error-on-exporttopdf-function/m-p/605017#M47273</guid>
      <dc:creator>DianeMcConnaughey</dc:creator>
      <dc:date>2012-08-03T13:39:17Z</dc:date>
    </item>
  </channel>
</rss>

