0

I have modified a code I found online to batch export a series of map documents (mxds) to ArcPublisher files (PMFs). I have all the relevant licenses and the code does "work", the only problem is the resultant PMF's are all empty.

I think I know where the problem lies, in that I think the code may not (well most likely is) be reading the data in the MXDs.

I have included the code:

 Protected Overrides Sub OnClick()

    Dim pGxDialog As IGxDialog
    Dim pGxObjectFilter As IGxObjectFilter
    Dim anythingSelected As Boolean
    Dim pGxMaps As IEnumGxObject
    Dim pGxMap As IGxMap
    Dim pGxFolders As IEnumGxObject
    Dim pGxFolder As IGxObject
    Dim strStartingLocation As String
    Dim lngMXDCount As Long
    Dim sFullPathName As String
    Dim pGxObject As IGxObject
    Dim pGxMapPageLayout As IGxMapPageLayout
    Dim pPageLayout As IPageLayout

    ' input mxds
    pGxObjectFilter = New GxFilterMaps
    pGxDialog = New GxDialog

    With pGxDialog
        .Title = "Select input MXDs"
        .AllowMultiSelect = True
    End With
    pGxDialog.ObjectFilter = pGxObjectFilter
    anythingSelected = pGxDialog.DoModalOpen(My.ArcMap.Application.hWnd, pGxMaps)
    If Not anythingSelected Then
        MsgBox("Cancel")
        Exit Sub
    End If

    ' starting location, name
    strStartingLocation = pGxDialog.FinalLocation.Parent.Name

    ' output folder
    pGxObjectFilter = New GxFilterBasicTypes
    pGxDialog = New GxDialog
    With pGxDialog
        .Title = "Select output folder"
        .AllowMultiSelect = False
        .StartingLocation = strStartingLocation
    End With
    pGxDialog.ObjectFilter = pGxObjectFilter
    anythingSelected = pGxDialog.DoModalOpen(My.ArcMap.Application.hWnd, pGxFolders)

    If anythingSelected Then
        pGxFolder = pGxFolders.Next
    Else
        MsgBox("Cancel")
        Exit Sub
    End If

    pGxMaps.Reset()

    pGxMap = pGxMaps.Next
    Do Until pGxMap Is Nothing
        lngMXDCount = lngMXDCount + 1
        pGxMap = pGxMaps.Next
    Loop
    If lngMXDCount = 0 Then Exit Sub

    With My.ArcMap.Application.StatusBar.ProgressBar
        .Message = "Exporting MXD to PMF..."
        .MinRange = 0
        .MaxRange = lngMXDCount
        .StepValue = 1
        .Show()
    End With

    pGxMaps.Reset()
    pGxMap = pGxMaps.Next

    Do Until pGxMap Is Nothing

        ''''new
        Dim publisherengine As IPMFPublish3 = New PublisherEngine
        Dim publishersettings As IPropertySet = publisherengine.GetDefaultPublisherSettings

        pGxObject = pGxMap

        pGxMapPageLayout = pGxMap
        pPageLayout = pGxMapPageLayout.PageLayout

        sFullPathName = pGxFolder.FullName & "\" & pGxObject.BaseName & ".pmf"


        Dim App As IApplication
        Dim mapdoc As IMxDocument

        App = My.ArcMap.ThisApplication
        mapdoc = App.Document

        Dim pagelayout As IPageLayout = mapdoc.PageLayout
        Dim defaultview As IActiveView = mapdoc.ActiveView
        Dim settings As IPropertySet = publishersettings
        Dim relativepaths As Boolean = True
        Dim document As String = sFullPathName

        publisherengine.Publish(pagelayout, defaultview, settings, relativepaths, document)

        ''''end

        My.ArcMap.Application.StatusBar.ProgressBar.Step()
        pGxMap = pGxMaps.Next

    Loop

    My.ArcMap.Application.StatusBar.ProgressBar.Hide()
    MsgBox("ArcPublisher tool has completed exporting: " & lngMXDCount & vbNewLine & "to the following directory: " & pGxFolder.FullName, MsgBoxStyle.OkOnly, "Process completed successfully")


    My.ArcMap.Application.CurrentTool = Nothing
End Sub
1

I'm guessing you are trying to run this as an AddIn button from within ArcMap?

First of all you obtain the page layout from the map then ignore it by using the page layout from the Active MapDocument. You also obtain the activeview from the Active MapDocument, not the document in your list of MXDs...

When connecting to other MapDocuments to do something with them you need to be using the IMapDocument interface. This allows you to manipulate mxds without ArcMap being open, but as you have ArcMap open and running code you had got yourself into a problem by using the incorrect object. An easy but frustrating mistake to make.

So below is the code corrected which you would insert after you reset the enumerator. As a side note I would suggest you name your pointer after the object and not what the object spits out as it makes your code very difficult to read. So in your case rename pGxMaps after the object it really is which would be pEnumGxObject. Then you and I know what you are actually talking about.

        pGxMaps.Reset()
        pGxMap = pGxMaps.Next


        Dim pMapDocument As IMapDocument

        Dim publisherengine As IPMFPublish3 = New PublisherEngine
        Dim publishersettings As IPropertySet = publisherengine.GetDefaultPublisherSettings

        Do Until pGxMap Is Nothing
            ' Create a full path name for pmf file
            pGxObject = pGxMap
            sFullPathName = pGxFolder.FullName & "\" & pGxObject.BaseName & ".pmf"

            ' Connect to MapDocument
            pMapDocument = New MapDocument
            pMapDocument.Open(pGxObject.FullName)

            ' Set properties based upon the MapDocument
            Dim defaultview As IActiveView = pMapDocument.ActiveView
            pPageLayout = pMapDocument.PageLayout
            Dim settings As IPropertySet = publishersettings
            Dim relativepaths As Boolean = True

            ' Publish
            publisherengine.Publish(pPageLayout, defaultview, settings, relativepaths, sFullPathName)

            'Update
            My.ArcMap.Application.StatusBar.ProgressBar.Step()
            pGxMap = pGxMaps.Next
            pMapDocument.Close()
        Loop
  • Hi @Hornbydd, thank you for the help! I have taken your code and have seen where I went wrong. It seems to work, I am getting an error (OLE_E_CANTCONVERT),however the PMF is still exported correctly. I will keep searching for answers, but you have really helped me out. Thanks K – Keagan Allan Nov 25 '14 at 11:03

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.