📄 sample vba code.mht
字号:
xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt">指北针</=
SPAN>和一个<SPAN=20
xmlns:user=3D"http://www.esri.com/ContentStudio"=20
xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt">图例</SPAN>=
2290;指北针和图例都是<SPA=
N=20
xmlns:user=3D"http://www.esri.com/ContentStudio"=20
xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt">地图元&#=
32032;</SPAN>的类型。地图元 =
032;是地图相关的对象ʌ=
92;=20
<P =
class=3DBreak></P>在本例中,你将=
;运行一个由VB编辑器࠵=
9;建的<SPAN=20
xmlns:user=3D"http://www.esri.com/ContentStudio"=20
xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt">宏</SPAN>。=20
<P class=3DBreak></P>
<P></P>
<H3>如何使用</H3>
<P class=3DBreak></P>
<P></P>
<P></P>
<OL>
<LI>启动ArcMap.=20
<P class=3DBreak></P>
=
<LI>打开一个现存的地Þ=
70;文件(.mxd),或将图&#=
23618;添加到空白的地图=
5991;件。=20
<LI>=93Tools=94菜单-->=93Macros=94-->=93Visual Basic =
Editor=94。=20
<P class=3DBreak></P>
<P =
class=3DBreak></P>这样便打开了Visual =
Basic Editor。=20
<P class=3DBreak></P>
=
<LI>展开project浏览器中你௚=
0;工程(地图文件)。=
;=20
<P class=3DBreak></P>
=
<LI>右击Project,指向Insert,单=
击Module=20
<P class=3DBreak></P>
=
<P>一个新的模块便被૿=
5;加到了project中,且Moudle1的&=
#20195;码窗口被打开。</P>
<P class=3DBreak></P>
=
<LI>将下列代码复制到É=
95;码窗口。=20
<P class=3DBreak></P>
<P></P><PRE class=3Dcode><CODE>Public Sub AddMapSurrounds()
Dim pMxDoc As IMxDocument
Dim pActiveView As IActiveView
Dim pEnv As IEnvelope
Dim pID As New UID
Dim pMapSurround As IMapSurround
Dim pMarkerNorthArrow As IMarkerNorthArrow
Dim pCharacterMarkerSymbol As ICharacterMarkerSymbol
Set pMxDoc =3D Application.Document
Set pActiveView =3D pMxDoc.PageLayout
Set pEnv =3D New Envelope
'Add a north arrow
pEnv.PutCoords 0.2, 0.2, 1, 1
pID.Value =3D "esriCore.MarkerNorthArrow"
Set pMapSurround =3D CreateSurround(pID, pEnv, "North Arrow", =
pMxDoc.FocusMap, pMxDoc.PageLayout)
'Change out the default north arrow
Set pMarkerNorthArrow =3D pMapSurround 'QI
Set pCharacterMarkerSymbol =3D pMarkerNorthArrow.MarkerSymbol 'clones =
the symbol
pCharacterMarkerSymbol.CharacterIndex =3D 200 'change the symbol
pMarkerNorthArrow.MarkerSymbol =3D pCharacterMarkerSymbol 'set it back
'Add a legend
'In this case just use the default legend
pEnv.PutCoords 7.5, 0.2, 8.5, 4
pID.Value =3D "esriCore.Legend"
Set pMapSurround =3D CreateSurround(pID, pEnv, "Legend", =
pMxDoc.FocusMap, pMxDoc.PageLayout)
'Refresh the graphics
pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
End Sub
Private Function CreateSurround(pID As UID, pEnv As IEnvelope, strName =
As String, _
pMap As IMap, pPageLayout As IPageLayout) As IMapSurround
Dim pGraphicsContainer As IGraphicsContainer
Dim pActiveView As IActiveView
Dim pMapSurroundFrame As IMapSurroundFrame
Dim pMapSurround As IMapSurround
Dim pMapFrame As IMapFrame
Dim pElement As IElement
'MapSurrounds are held in a MapSurroundFrame
'MapSurroundFrames are related to MapFrames
'MapFrames hold Maps
Set pGraphicsContainer =3D pPageLayout
Set pMapFrame =3D pGraphicsContainer.FindFrame(pMap)
Set pMapSurroundFrame =3D pMapFrame.CreateSurroundFrame(pID, Nothing)
pMapSurroundFrame.MapSurround.Name =3D strName
'Set the geometry of the MapSurroundFrame to give it a location
'Activate it and add it to the PageLayout's graphics container
Set pElement =3D pMapSurroundFrame
Set pActiveView =3D pPageLayout
pElement.Geometry =3D pEnv
pElement.Activate pActiveView.ScreenDisplay
pGraphicsContainer.AddElement pElement, 0
Set CreateSurround =3D pMapSurroundFrame.MapSurround
End Function</CODE></PRE><BR>
<P class=3DBreak></P>
<P></P>
<P></P>
<LI>最小化或关闭Visual Basic =
Editor。=20
<P class=3DBreak></P>
<LI>切换到版面视图。=20
=
<LI>在ArcMap中,选择工具菜=
;单中的Macros。=20
<P class=3DBreak></P>
=
<LI>在Macros对话框中,单击=
;Macros的向下键头选Project。=20
<P class=3DBreak></P>
<LI>在Macro =
name对话框中单击Module1.AddMapSurroun=
ds。=20
<LI>单击Run。 </LI></OL>
<P class=3DBreak></P>
<P></P>
<TABLE cellPadding=3D5 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD>
<H3>提示</H3>
<UL>
=
<LI>请确定VB中的代码是=
0197;以上步骤中的格式=
986;现。例如,你可能Ƃ=
56;要自己加些回车。=20
</LI></UL></TD></TR></TBODY></TABLE></DIV>
<DIV class=3Dsubhead id=3DhowSub3><A name=3DhowSub3Anchor></A>
<H3><A onclick=3D"expandIt('howSub3')"=20
href=3D"file:///C:/Documents%20and%20Settings/YAZI/桌面/Dechm=
s/定制ArcMap和ArcCatalog/sample_vba_code.htm#howSub3Anc=
hor"><IMG=20
height=3D11 alt=3D"expand/collapse item"=20
src=3D"file:///C:/Documents%20and%20Settings/YAZI/桌面/Dechms=
/customizing_arcmap_and_arccatalog/small_arrow_up.gif"=20
width=3D11 border=3D0 name=3DimEx></A> =
计算选中的多边形的&=
#38754;积</H3></DIV>
<DIV class=3Dsubcontent id=3DhowSub3Content>
<H3>描述</H3>
<P=20
class=3DBreak>该范例将计算所=
6377;选中的图形的面积=
290;首先,选中一个或ä=
10;个多边形要素,可ߣ=
7;有几种方法,包括使=
;用一个查询或使用一=
个搜索部分的工具。&=
#28982;后,单击在工具栏&#=
19978;的工具按钮(可以=
3258;己创建)。这个程=
207;运用DO=20
LOOP循环去计算整个选È=
13;的图形面积,而且๡=
6;用 message box =
把结果显示出来。<BR>ß=
12;本例子中,你将添ࡃ=
2;一个按钮并为它编写=
;代码。</P>
<P class=3DBreak></P>
<P></P>
<H3>如何使用</H3>
<P class=3DBreak></P>
<P></P>
<OL>
<LI>启动ArcMap.=20
<P class=3DBreak></P>
=
<LI>打开一个现存的地Þ=
70;文件(.mxd),或将图&#=
23618;添加到空白的地图=
5991;件。=20
<P class=3DBreak></P>
<LI>=93Tools=94菜单-->=93Customize=94。=20
<P class=3DBreak></P>
<LI>点击=93Commands=94标签。=20
<P class=3DBreak></P>
=
<LI>点击=93Save=94组合框旁的=
9979;箭头,并选择新命=
196;将要保存的地图。=20
<P class=3DBreak></P>
=
<LI>滚动=93类别=94列表框,=
;点击=93UIControls=94。=20
<P class=3DBreak></P>
<LI>点击=93New UIControl=94。=20
<P class=3DBreak></P>
=
<LI>点击选择一个UIControl类=
411;。=20
<P class=3DBreak></P>
<LI>点击=93Create=94。=20
<P class=3DBreak></P>
=
<LI>将=93Commands=94列表框中新建=
;的=93Project.UIButtonControl1=94拖动到任&#=
24847;工具栏上。=20
<P class=3DBreak></P>
<LI>点击=93Create=94。=20
<P class=3DBreak></P>
=
<LI>右击刚制作好的按ż=
62;,点击=93View Source=94。=20
<P =
class=3DBreak></P>这样便打开了Visual =
Basic Editor。=20
<P class=3DBreak></P>
=
<LI>在代码窗口中,点Ñ=
87;程序框旁的下三角ᦀ=
8;在窗体的右边),选=
;择=93Click=94。=20
<P =
class=3DBreak></P>这样便为你的过=
;程提供了头尾的代码=
。=20
<P class=3DBreak></P>
=
<LI>复制以下代码并粘ũ=
48;在Click事件过程中。=20
<P class=3DBreak></P>
<P></P><PRE class=3Dcode><CODE>Dim pMxDoc As IMxDocument
Set pMxDoc =3D ThisDocument
Dim pUID As New UID
pUID =3D "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" 'IGeoFeatureLayer IID
Dim pEnumLayer As IEnumLayer
Set pEnumLayer =3D pMxDoc.FocusMap.Layers(pUID, True)
pEnumLayer.Reset
Dim pFeatureLayer As IFeatureLayer
Dim pFeatureSelection As IFeatureSelection
Dim pFeatureCursor As IFeatureCursor
Dim pFeature As IFeature
Dim pArea As IArea
Dim dTotalArea As Double
Set pFeatureLayer =3D pEnumLayer.Next
Do Until (pFeatureLayer Is Nothing)
If (pFeatureLayer.FeatureClass.ShapeType =3D esriGeometryPolygon) Then
Set pFeatureSelection =3D pFeatureLayer
If (pFeatureSelection.SelectionSet.Count <> 0) Then
pFeatureSelection.SelectionSet.Search Nothing, True, =
pFeatureCursor
Set pFeature =3D pFeatureCursor.NextFeature
Do Until (pFeature Is Nothing)
Set pArea =3D pFeature.Shape
dTotalArea =3D dTotalArea + pArea.Area
Set pFeature =3D pFeatureCursor.NextFeature
Loop
End If
End If
Set pFeatureLayer =3D pEnumLayer.Next
Loop
MsgBox "Total Area for selected polygon features =3D " & =
CStr(dTotalArea)</CODE></PRE><BR>
<P class=3DBreak></P>
<P></P>
<LI>关闭the Visual Basic Editor.=20
<P class=3DBreak></P>
=
<LI>在ArcMap中选取一些多边=
;形要素。可以有很多=
方法,包括运用一个&=
#26597;询或select features工具=20
<P class=3DBreak></P>
=
<LI>单击新按钮,获取ť=
45;算出的整个面积 </LI></OL>
<P class=3DBreak></P>
<P></P>
<P></P>
<TABLE cellPadding=3D5 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD>
<H3>提示</H3>
<UL>
=
<LI>请确定VB中的代码是=
0197;以上步骤中的格式=
986;现。例如,你可能Ƃ=
56;要自己加些回车。 =
</LI></UL>
<P></P></TD></TR></TBODY></TABLE></DIV>
<DIV class=3Dsubhead id=3DhowSub4><A name=3DhowSub4Anchor></A>
<H3><A onclick=3D"expandIt('howSub4')"=20
href=3D"file:///C:/Documents%20and%20Settings/YAZI/桌面/Dechm=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -