| Message |
I can’t get the map object to ‘do’ anything. As a test I just want to via code open ArcMap, or a MapDocument or whatever is best, change the scale of the map and export to pdf. I can get to the map and return layercount etc, I can get to the pagelayout and change text elements, but every time I export the map it is the original extent and not the updated extent from a scale change. I have attempted this with iGxFile, and iMapDocument, and launching ArcMap via iApplication.OpenDocument… I’m missing something.
Thanks,
Brian |
| |
Attempts are like:
Dim myfile As String = "C:\temp\test.mxd"
Dim pGxFile As IGxFile
Dim pGxPageLayout As IGxMapPageLayout
Dim pActiveview As IActiveView
Dim pMap As IMap
pGxFile = New GxMap
pGxFile.Path = myfile
pGxFile.Open()
pGxPageLayout = pGxFile
pActiveview = pGxPageLayout.PageLayout
pMap = pActiveview.FocusMap
pMap.MapScale = 12000
pActiveview.Refresh()
export(pGxPageLayout.PageLayout, "C:\temp" & "\" & "test.pdf", 300)
pGxFile.Close(False)
OR
Dim pMapDocument As IMapDocument
Dim sFilePath As String = "C:\temp\test.mxd"
Dim pMap As IMap
Dim pActiveview As IActiveView
Dim pPageLayout As IPageLayout
pMapDocument = New MapDocument
pMapDocument.Open(sFilePath)
pPageLayout = pMapDocument.PageLayout
pMap = pMapDocument.Map(0)
pMap.MapScale = 12000
pActiveview = pPageLayout
pActiveview.Refresh()
export(pPageLayout, "C:\temp" & "\" & "test.pdf", 300)
pMapDocument.Close()
'The export function is from the forums
Sub export(ByVal pPageLayout As IPageLayout, ByVal sExportPath As String, ByVal lDPI As Long)
' writes out the pagelayout to a pdf
Dim pExporter As IExporter
pExporter = New PDFExporter
Dim pPixelEnv As IEnvelope
pPixelEnv = New Envelope
pPixelEnv.PutCoords(0, 0, lDPI * PageExtent(pPageLayout).UpperRight.X, _
lDPI * PageExtent(pPageLayout).UpperRight.Y)
pExporter.PixelBounds = pPixelEnv
pExporter.Resolution = lDPI
pExporter.ExportFileName = sExportPath
pExporter.ClipToGraphicExtent = False
Dim pFME As IFontMapEnvironment
Dim pFMC As IFontMapCollection
Dim pFM As IFontMap2
pFME = pExporter
pFMC = pFME.FontMapCollection
pFM = New FontMap
pFM.SetMapping("Arial", "Helvetica")
pFMC.add(pFM)
pFM = New FontMap
pFM.SetMapping("ESRI North 9", "Helvetica")
pFMC.add(pFM)
pFM = New FontMap
pFM.SetMapping("Arial Bold", "Helvetica-Bold")
pFMC.add(pFM)
pFM = New FontMap
pFM.SetMapping("Arial Black", "Helvetica")
pFMC.add(pFM)
pFM = New FontMap
pFM.SetMapping("Arial Narrow", "Helvetica")
pFMC.add(pFM)
pFM = New FontMap
pFM.SetMapping("Arial Italic", "Helvetica-Oblique")
pFMC.add(pFM)
pFM = New FontMap
pFM.SetMapping("Times New Roman", "Times-Roman")
pFMC.add(pFM)
pFM = New FontMap
pFM.SetMapping("Times New Roman Italic", "Times-Italic")
pFMC.add(pFM)
' (device coordinates origin is upper left, ypositive is down)
Dim tExpRect As tagRECT
tExpRect.Left = pExporter.PixelBounds.LowerLeft.X
tExpRect.bottom = pExporter.PixelBounds.UpperRight.Y
tExpRect.Right = pExporter.PixelBounds.UpperRight.X
tExpRect.Top = pExporter.PixelBounds.LowerLeft.Y
Dim hDc As Long
hDc = pExporter.StartExporting
Dim pAV As IActiveView
pAV = pPageLayout
pAV.Output(hDc, lDPI, tExpRect, Nothing, Nothing)
pExporter.FinishExporting()
End Sub
Function PageExtent(ByVal pPageLayout As IPageLayout) As IEnvelope
Dim dWidth As Double, dHeight As Double
pPageLayout.Page.QuerySize(dWidth, dHeight)
Dim pEnv As IEnvelope
pEnv = New Envelope
pEnv.PutCoords(0.0#, 0.0#, dWidth, dHeight)
PageExtent = pEnv
End Function |