Sub SwitchSelection()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap
'Get the Feature Selection
Dim pFLayer As IFeatureLayer
Set pFLayer = pMap.Layer(0)
Dim pFSel As IFeatureSelection
Set pFSel = pFLayer
'Get the set of selected features
Dim pSelFeats As ISelectionSet
Set pSelFeats = pFSel.SelectionSet
Debug.Print "Selected Features " & pSelFeats.Count
'Get a selection set of all features
Dim pAllFeats As ISelectionSet
Set pAllFeats = pFLayer.FeatureClass.Select(Nothing, _
esriSelectionTypeIDSet, esriSelectionOptionNormal, Nothing)
Debug.Print "Total Features " & pAllFeats.Count
'Switch the Selection
Dim pNewSel As ISelectionSet
pAllFeats.Combine pSelFeats, esriSetDifference, pNewSel
Debug.Print "New Selection " & pNewSel.Count
Set pFSel.SelectionSet = pNewSel
pDoc.ActiveView.Refresh
End Sub
5 关闭 Visual Basic 编辑器。
6 添加数据到ArcMap并且选择一些要素。
7 运行代码。
A 点击工具> 宏 > 显示宏对话框。
B 选择一个宏,然后点击运行。
1 个回复
EsriSupport
赞同来自:
内容: 使用IselectionSet::Combine的方法得到选择集要素和图层中所有要素的差别。
1 启动Arcmap.
2 打开Visual Basic的编辑器
在ArcMap, 工具菜单> 宏> Visual Basic 编辑器.
3 在工程浏览器窗口,展开Project.mxt,然后选择ArcMap objects > ThisDocument. 右键,选择View code.
在ThisDocument 代码模块中的代码仅仅是在当前的地图文档中运行。如果要在所有的地图文档中都存储这些代码,请打开在Normal.mxt中的ThisDocument代码模块。
4 拷贝下面的代码到代码模块。
Sub SwitchSelection()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap
'Get the Feature Selection
Dim pFLayer As IFeatureLayer
Set pFLayer = pMap.Layer(0)
Dim pFSel As IFeatureSelection
Set pFSel = pFLayer
'Get the set of selected features
Dim pSelFeats As ISelectionSet
Set pSelFeats = pFSel.SelectionSet
Debug.Print "Selected Features " & pSelFeats.Count
'Get a selection set of all features
Dim pAllFeats As ISelectionSet
Set pAllFeats = pFLayer.FeatureClass.Select(Nothing, _
esriSelectionTypeIDSet, esriSelectionOptionNormal, Nothing)
Debug.Print "Total Features " & pAllFeats.Count
'Switch the Selection
Dim pNewSel As ISelectionSet
pAllFeats.Combine pSelFeats, esriSetDifference, pNewSel
Debug.Print "New Selection " & pNewSel.Count
Set pFSel.SelectionSet = pNewSel
pDoc.ActiveView.Refresh
End Sub
5 关闭 Visual Basic 编辑器。
6 添加数据到ArcMap并且选择一些要素。
7 运行代码。
A 点击工具> 宏 > 显示宏对话框。
B 选择一个宏,然后点击运行。
创建时间:2004-08-09
最近更新:2004-08-09
【原文链接】
http://support.esrichina.com.cn/2004/0809/387.html
要回复问题请先登录或注册