How to package a published map


The following VBA code creates a published map and packages it using the publisher extension.

How to use

  1. Run ArcMap and Open a map
  2. Add a custom UIToolControl to ArcMap.
  3. Click ArcMap Tools menu and click Customize...
  4. On the Customize dialog click the Commands tab.
  5. Click UIControls in the Categories list box.
  6. Click New UIControl button and create a UIButtonControl.
  7. Select the UIButtonControl from the Commands list box and drag it onto an ArcMap Toolbar.
  8. Right click the UIButtonControl on the toolbar and click View Source.
  9. Paste the code between the UIButtonControl_Click and End Sub lines.
  10. Click Tool menu references and check ESRI Publisher Object Library, ESRI PublisherUI Object Library, ESRI Carto Object Library, ESRI System Object Library, ESRI ArcMap Object Library, ESRI ArcMapUI Object Library and Microsoft Scripting Runtime
  11. Close VBA
  12. Click the Custom Button you added and the map will be published and packaged to your C Drive. If you do not have a C drive change the code to an applicable drive on your computer.
[VBA]
'Sample that publishes the current map and then packages it.
'Publisher extension must be installed and a publisher license
'is needed.

'Prep the map
Dim pMxDocument As IMxDocument
Set pMxDocument = ThisDocument

'Set up the publisher
Dim pExtension As IPMF
Dim pUID As IUID
Set pUID = New UID
pUID.Value = "{8AEE0DE1-535C-4788-95C8-1659444D4C02}"
Set pExtension = Application.FindExtensionByCLSID(pUID)

'Create Folder to hold the published map
Dim fso As New FileSystemObject, fldr As Folder, s As String
fso.CreateFolder ("c:\publisher_sample")

'Set up the publisher engine for packaging
Dim pPE As IPMFPackage
Set pPE = New PackagerEngine

'Note the hardcoded path.  This is the location the published map
'will be written to. Change this to an appropriate path for your
'computer. The map will be published using the current publisher
'setttings.

pExtension.PMFPublish "c:\publisher_sample\sample.pmf"

'Create a folder to hold the data package.
fso.CreateFolder ("c:\publisher_sample\package")

'Specify the data package location
Dim pSettings As IPropertySet
Set pSettings = pPE.GetDefaultPackagerSettings()
pSettings.SetProperty "Package Directory", "c:\publisher_sample\package"

'Put the published map to package in an array
Dim pArr As IStringArray
Set pArr = New StrArray
pArr.Add "c:\publisher_sample\sample.pmf"

'Set the output data format to compressed and encrypted
pSettings.SetProperty "Vector Type", esriAPEVectorTypeCompressedEncrypted

'Set the vector clip type to only include features that intersect the data frame
pSettings.SetProperty "Vector Clip Type", esriAPEVectorClipTypeIncludeFeatures


'Set Cancel Tracker
Dim pCT As ITrackCancel
Set pCT = New CancelTracker

'Package the published map
pPE.Package pSettings, pCT, pArr

'Use message box to notify the completion of data packaging
MsgBox "Data Packaging has been completed"