ArcGIS Engine 怎样给PageLayout替换模板

                                         ArcGIS Engine 怎样给PageLayout替换模板

在打印出图时,常常需要更换已有的模板(mxt),这时数据并不改变。在ArcMap里面有一个替换模板的工具,但是在Engine里面却没有一个能直接替换模板的接口,而是需要读取新模板,取出模板里面的各个要素,然后替换掉原模板里面是相应要素。

Sub changelayout()
Dim pDoc As IMxDocument
Set pDoc = Application.Document
Dim pMap As IMap
Set pMap = pDoc.FocusMap
Dim pPageLayout As IPageLayout
Set pPageLayout = pDoc.PageLayout
'读取新模板
Dim pNewDoc As IMapDocument
Set pNewDoc = New MapDocument
pNewDoc.Open "C:Program FilesArcGISBinTemplatesLandscapeModern.mxt"
Dim pTempMap As IMap
Dim pTempPagelayout As IPageLayout
Set pTempPagelayout = pNewDoc.PageLayout
'Set pTempMap = pNewDoc.Map
Dim pTempPage As IPage
Set pTempPage = pTempPagelayout.Page

Dim pCurPage As IPage
Set pCurPage = pPageLayout.Page

'替换单位
pCurPage.Units = pTempPage.Units
'exchange page orientation
pCurPage.Orientation = pTempPage.Orientation
'替换页面尺寸
Dim dWidth As Double
Dim dHeight As Double
pTempPage.QuerySize dWidth, dHeight
pCurPage.PutCustomSize dWidth, dHeight

'删除当前Layout中除了mapframe外的所有elements
Dim pGraphicsCont As IGraphicsContainer
Dim pElement As IElement
Set pGraphicsCont = pPageLayout
pGraphicsCont.Reset
Set pElement = pGraphicsCont.Next
Do Until pElement Is Nothing
If TypeOf pElement Is IMapFrame Then
Dim pMapFrame As IMapFrame
Dim pMapFrameElement As IElement
Set pMapFrameElement = pElement
Set pMapFrame = pElement
Else
pGraphicsCont.DeleteElement pElement
pGraphicsCont.Reset
End If
Set pElement = pGraphicsCont.Next


Loop

'遍历模板的PageLayout中的所有元素,并且替换当前PageLayout中的所有元素
Dim pTempGraphicsCont As IGraphicsContainer
Set pTempGraphicsCont = pTempPagelayout
pTempGraphicsCont.Reset
Set pElement = pTempGraphicsCont.Next
Dim pArray As IArray
Set pArray = New esriSystem.Array
Do Until pElement Is Nothing
If TypeOf pElement Is IMapFrame Then
pMapFrameElement.Geometry = pElement.Geometry
Else
If TypeOf pElement Is IMapSurroundFrame Then
Dim pTempMapSurroundFrame As IMapSurroundFrame
Dim pTempMapSurround As IMapSurround
Set pTempMapSurroundFrame = pElement
Set pTempMapSurroundFrame.MapFrame = pMapFrame
Set pTempMapSurround = pTempMapSurroundFrame.MapSurround
pMap.AddMapSurround pTempMapSurround
End If
pArray.Add pElement
End If
Set pElement = pTempGraphicsCont.Next
Loop

Dim pElementCount As Long
pElementCount = pArray.Count
Dim i As Long
'将模板PageLayout中的其它元素(除了MapFrameElement和MapSurroundFrame外的元素)添加到当前PageLayout中去
For i = 0 To pElementCount - 1
pGraphicsCont.AddElement pArray.Element(pElementCount - 1 - i), 0
Next i
pDoc.ActiveView.Refresh

End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值