I am using a library called PubPy which serves to automate the export of TerraGo Publisher for ArcGIS. This is my example Python script:

import os
import sys
import arcpy
from pubpy.geopdf_export.api import ExportMXDToGeoPDF
        mxd = r"D:\F14C21D\F14C21D_2018_5_1.mxd"
        pdf = r"D:\F14C21D_2018_5_1.pdf"
        ExportMXDToGeoPDF(mxd, pdf)
        print "Error: {0}".format(sys.exc_info()[1])

When the script executes "ExportMXDToGeoPDF (mxd, pdf)" it enters the process ExportMXDToGeoPDF which is the following code that is already created for the PubPy library:

def ExportMXDToGeoPDF(mxd_path, geopdf_path):
   """ExportMXDToGeoPDF(mxd_path, geopdf_path)
     Export a pre-configured MXD to GeoPDF file format. Export configuraion is stored in the MXD.

         A string that represents the path and filename of the MXD to export.

         A string that represents the path and filename of the GeoPDF to create."""

    import os.path
    import comtypes
    from comtypes.client import CreateObject
    from comtypes.gen import esriCarto
    from comtypes.gen import esriOutput
    from comtypes.gen import MAP2PDF_ArcGIS_GeoPDF_Export

    if not isinstance(mxd_path, basestring):
        raise ValueError('mxd_path must be a path.')

    if not isinstance(geopdf_path, basestring):
        raise ValueError('geopdf_path must be a path.')

    geopdf_path = os.path.abspath(geopdf_path)

    md = CreateObject("esriCarto.MapDocument", \
                                  comtypes.CLSCTX_INPROC_SERVER, \
                                  None, \
    md.Open(mxd_path, None)
    layout = md.PageLayout

        export = CreateObject("map2pdf.ExportGeoPDF", \
                                      comtypes.CLSCTX_INPROC_SERVER, \
                                      None, \
        raise RuntimeError("GeoPDF exporer creation failed. Are you licensed?")

    # always set IExportGeoPDF2.ActiveView first
    export.ExportFileName = geopdf_path
    exportGeoPDF2 = 
    exportGeoPDF2.ActiveView = layout

    pe = CreateObject("esriCarto.PrintAndExport", \
                                  comtypes.CLSCTX_INPROC_SERVER, \
                                  None, \
        pe.Export(layout, export, 300, 0, 0)
    except Exception as e:
        raise RuntimeError("GeoPDF export failed. Is the output path accessible? Is the file already open? " + str(e))

    del pe
    del export
    del md

    # end ExportMXDToGeoPDF

All good but when you get to execute "pe.Export (layout, export, 300, 0, 0)" starts exporting the GeoPDF and then running the process thunders and marks the following error:

enter image description here

I already do several types of tests and it does not work, I hope and you can help me, regards.

One of the causes of the problem may be the following Python script for ArcGIS 10.6 which is located in the following path "C: \ Python27 \ ArcGIS10.6 \ Lib \ site-packages \ comtypes-1.1.2-py2.7. egg \ comtypes \ __ init__.py ".

The problem is in this part of the Script:

def __getattr__(self, name):
    """Implement case insensitive access to methods and properties"""
        fixed_name = self.__map_case__[name.lower()]
    except KeyError:
        raise AttributeError(name)
    if fixed_name != name: # prevent unbounded recursion
        return getattr(self, fixed_name)
    raise AttributeError(name)

    # __setattr__ is pretty heavy-weight, because it is called for
    # EVERY attribute assignment.  Settings a non-com attribute
    # through this function takes 8.6 usec, while without this
    # function it takes 0.7 sec - 12 times slower.
    # How much faster would this be if implemented in C?

At the moment of obtaining the value of the following variable "fixed_name = self .__ map_case __ [name.lower ()]", it sends the following error:

enter image description here

The values of the variables are the following:

Name = '_com_pointers_'
Self = <POINTER(IPageLayout) ptr=0xd92ca98 at 10633710>
self.__map_case__ =  {'_get_verticalsnapguides': '_get_VerticalSnapGuides', 
'replacemaps': 'ReplaceMaps', '_set_aligntomargins': '_set_AlignToMargins', 
'_get_snapgrid': '_get_SnapGrid', '_get_zoompercent': '_get_ZoomPercent', 
'verticalsnapguides': 'VerticalSnapGuides', 'zoomtowhole': 'ZoomToWhole', 
'focusnextmapframe': 'FocusNextMapFrame', 'rulersettings': 'RulerSettings', 
'aligntomargins': 'AlignToMargins', '_get_page': '_get_Page', 
'_get_rulersettings': '_get_RulerSettings', '_get_aligntomargins': 
'_get_AlignToMargins', 'horizontalsnapguides': 'HorizontalSnapGuides', 
'snapgrid': 'SnapGrid', 'zoomtowidth': 'ZoomToWidth', 'zoomtopercent': 
'ZoomToPercent', 'focuspreviousmapframe': 'FocusPreviousMapFrame', 'page': 
'Page', '_get_horizontalsnapguides': '_get_HorizontalSnapGuides', 
'zoompercent': 'ZoomPercent'}

Can you help me with this error?


The problem that does not Exports the GeoPDF with PubPy is because it has enabled the option of rotating in the layers of point type, this option must be as "None".

enter image description here

I already reported it to the TerraGo Publisher Support and they determined that it is a bug on the part of the PubPy library and they filed the Bug, when they have answers they will inform me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.