Problem Exporting PDF Layout from AcrMap 10 using vb.net...

464
0
03-05-2014 03:48 PM
RobertKoch
New Contributor
Hi,

I have some vb.net code which worked in ArcMap 9.3.1 but fails in 10.2, and was hoping someone may be able to shed some light on the matter.

I'm using code which started its life as part of the DS Mapbook add on.

It creates a new ESRI.ArcGIS.esriSystem.CategoryFactory and sets the CategoryID to esriExportsCat.
It then loops thought the CategoryFacotry creating an exporter object for supported export file type (in this case the target is PDF).
However after, creating exporter objects for BMP, GIF and EPS, the loop crashes with the following error:
Unable to cast COM Object of type 'System._ComObject to interface type 'ESRI.ArcGIS.Output.IExport'...

[ATTACH=CONFIG]31969[/ATTACH]

Can anybody help?

I've posed the function below. The parameter string "PDF" is being passed to the function.


Private Function GetTheLastExport(ByRef sExportType As String) As ESRI.ArcGIS.Output.IExport
        On Error GoTo ErrorHand

        Dim pTempExport As ESRI.ArcGIS.Output.IExport
        Dim i As Short
        Dim esriExportsCat As New ESRI.ArcGIS.esriSystem.UID
        Dim pCategoryFactory As ESRI.ArcGIS.esriSystem.ICategoryFactory
        Dim TempExportersCol As New Collection
        Dim pSettingsInRegistry As ESRI.ArcGIS.Output.ISettingsInRegistry
        Dim sLastUsedExporterName As String
        Dim lLastUsedExporterPriority As Integer

        'Use a Category Factory object to create one instance of every class registered
        ' in the "ESRI Exports" category.
        'Component Category: "ESRI Exports" = {66A7ECF7-9BE1-4E77-A8C7-42D3C62A2590}
344:    esriExportsCat.Value = "{66A7ECF7-9BE1-4E77-A8C7-42D3C62A2590}"
345:    pCategoryFactory = New ESRI.ArcGIS.esriSystem.CategoryFactory
346:    pCategoryFactory.CategoryID = esriExportsCat

        'As each exporter object is created, add it to a vb collection object for later use.
        ' Use each exporter object's Priority property as a unique static key for later
        ' access to each object in the collection.  Because some exporters change their file
        ' extension based on settings (eg. SVG), we should read and sync the registry values
        ' for each exporter after it is created.
353:    pTempExport = pCategoryFactory.CreateNext
354:    Do While Not pTempExport Is Nothing
355:        If pTempExport.Name = sExportType Then
356:            Exit Do
357:        End If
            MsgBox(pTempExport.Name)
            'XXX crashing on next line (never gets to PDF) 
359:        pTempExport = pCategoryFactory.CreateNext
360:    Loop


        'Set the exporter properties to whatever they were for the last user
363:    pSettingsInRegistry = pTempExport
364:    If Not pSettingsInRegistry Is Nothing Then
365:        pSettingsInRegistry.RestoreForCurrentUser("Software\ESRI\Export\ExportObjectsParams")
366:    End If

368:    GetTheLastExport = pTempExport

        Exit Function
ErrorHand:
372:    MsgBox("DSMapBookExt_GetTheLastExport - " & Erl() & " - " & Err.Description)
    End Function
0 Kudos
0 Replies