You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects General forum

Open AM-Pan to Feature -ExportPDF-Close   Brian Bottoms Aug 10, 2006
Re: Open AM-Pan to Feature -ExportPDF-Close   Miles Hitchen Aug 10, 2006
Re: Open AM-Pan to Feature -ExportPDF-Close   Brian Bottoms Aug 10, 2006
Re: Open AM-Pan to Feature -ExportPDF-Close   Miles Hitchen Aug 10, 2006
Re: Open AM-Pan to Feature -ExportPDF-Close   Brian Bottoms Aug 17, 2006
Re: Open AM-Pan to Feature -ExportPDF-Close   Miles Hitchen Aug 17, 2006
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Open AM-Pan to Feature -ExportPDF-Close 
Author Brian Bottoms 
Date Aug 10, 2006 
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
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Open AM-Pan to Feature -ExportPDF-Close 
Author Miles Hitchen 
Date Aug 10, 2006 
Message Hi Brian,

Just something off the top of my head, but have you tried refreshing the FcousMap (after changeing the scale) as well as the PageLayout before calling the export function?

Cheers,
Miles.
 
  Miles Hitchen
Software Engineer
Geospatial Team
Ordnance Survey
UK
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Open AM-Pan to Feature -ExportPDF-Close 
Author Brian Bottoms 
Date Aug 10, 2006 
Message Hi Miles,
I interpreted your suggestion to be to switch the activeview to the map object and call refresh there as well as doing so when the activeview is the pagelayout. I gave it a shot, but it didn’t change anything.
Thanks,
Brian
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Open AM-Pan to Feature -ExportPDF-Close 
Author Miles Hitchen 
Date Aug 10, 2006 
Message Hi Brian,

I've just tested your code and it's very odd that itdoesn't change the extents. I added some code that sets the extents of the active view to the equivelant of what it would be if you set the mapscale to 1200. It should work...!

Cheers,
Miles.
 
 
Dim pMapDocument As IMapDocument
Dim sFilePath As String = "C:\temp\test.mxd"
Dim pMap As IMap
Dim pActiveview As IActiveView
Dim pPageLayout As IPageLayout
Dim pEnv As IEnvelope

pMapDocument = New MapDocument
pMapDocument.Open (sFilePath)
pPageLayout = pMapDocument.PageLayout
pMap = pMapDocument.Map(0)

' **** New code ****
pActiveview = pMap
pEnv = pActiveview.Extent
pEnv.Expand 1200 / pMap.MapScale, 1200 / pMap.MapScale, True
pActiveview.Extent = pEnv
pActiveview.Refresh
' ******************

pActiveview = pPageLayout
pActiveview.Refresh()
export(pPageLayout, "C:\temp" & "\" & "test.pdf", 300)
pMapDocument.Close()
 
  Miles Hitchen
Software Engineer
Geospatial Team
Ordnance Survey
UK
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Open AM-Pan to Feature -ExportPDF-Close 
Author Brian Bottoms 
Date Aug 17, 2006 
Message Hello Miles,

I ended up sending my question to esri support (Kevin T answered it). I needed a Win API call to get it done. Below is the code that works. I discarded the previous export function and wrote one using the newer IExport. The code is actually in a .net application that loops mxds, panning around, changing info and exporting. It’s kind of a 1 click for many maps thing. I appreciate your help, without it I wouldn’t have at least believed that I was truly accessing the map object (it was driving me insane).

Brian
www.geoelement.com 
 
Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Sub ExportMapAtSpecificScale()
Dim pMapDocument As IMapDocument
Dim sFilePath As String
Dim pMap As IMap
Dim pActiveview As IActiveView
Dim pPageLayout As IPageLayout

  sFilePath = "C:\test.mxd"
  Set pMapDocument = New MapDocument
  pMapDocument.Open (sFilePath)
  Set pPageLayout = pMapDocument.PageLayout
  Set pMap = pMapDocument.Map(0)
  Set pActiveview = pPageLayout
  pActiveview.Activate GetDesktopWindow()
  pMap.MapScale = 12000
  pActiveview.Refresh
  export pPageLayout, "C:\temp\test.pdf", 400
  pMapDocument.Close

End Sub
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Open AM-Pan to Feature -ExportPDF-Close 
Author Miles Hitchen 
Date Aug 17, 2006 
Message Hi Brian,

Glad you got a fix for it in the end and thanks for sharing it.

Cheers,
Miles.
 
  Miles Hitchen
Software Engineer
Geospatial Team
Ordnance Survey
UK