HOW TO
Instructions provide sample code which will display only a selected set of features from a given feature class.
Note:
Code in the Project's ThisDocument code module will only run in the current map document. If you want to store the code in all your map documents, open the Normal.mxt ThisDocument code module instead.
Code:
Sub Main()
Dim pDoc As IMxDocument
Dim pLayer As IGeoFeatureLayer
Dim pFS As IFeatureSelection
Dim pSS As ISelectionSet
Set pDoc = Application.Document
'Make certain that the layer is selected in the TOC
Set pLayer = pDoc.SelectedLayer
Set pFS = pLayer 'QI
Set pSS = pFS.SelectionSet
DisplayOnlySelectedFeatures pLayer, pSS
'Refresh Data Frame
pDoc.ActiveView.Refresh
End Sub
Public Sub DisplayOnlySelectedFeatures(pGlayer As IGeoFeatureLayer _
, pSelectionset As ISelectionSet)
'Declare variables
Dim pFCEntire As IFeatureCursor
Dim pSelFC As IFeatureCursor
Dim lEntireOID As Long
Dim lSelOID As Long
Dim pFeatureIDSet As IFeatureIDSet
Dim pEntireEnumId As IEnumIDs
Dim pSelEnumIds As IEnumIDs
Dim pEntireSelSet As ISelectionSet
'set feature cursors for entire feature class and the selectionset
Set pFCEntire = pGlayer.FeatureClass.Search(Nothing, False)
pSelectionset.Search Nothing, False, pSelFC
'Enumerate through the selectionsets to get the ids
Set pSelEnumIds = pSelectionset.IDs
pSelEnumIds.Reset
lSelOID = pSelEnumIds.Next
Set pEntireSelSet = pGlayer.FeatureClass.Select(Nothing, _
esriSelectionTypeHybrid, esriSelectionOptionNormal, Nothing)
Set pEntireEnumId = pEntireSelSet.IDs
pEntireEnumId.Reset
lEntireOID = pEntireEnumId.Next
Set pFeatureIDSet = New FeatureIDSet
'Loop through Entire feature layer's oids and
'write them to the featureidset
Do Until lEntireOID = -1
pFeatureIDSet.Add lEntireOID
lEntireOID = pEntireEnumId.Next
Loop
'Loop through the selected feature's oids and check to see
'if the featureidset contains any of them.
'If so, remove them.
Do Until lSelOID = -1
If pFeatureIDSet.Contains(lSelOID) Then
pFeatureIDSet.Remove (lSelOID)
End If
lSelOID = pSelEnumIds.Next
Loop
'Set the exclusion featureidset to that of the geofeaturelayer
Set pGlayer.ExclusionSet = pFeatureIDSet
End Sub
Note:
These features can be restored by right-clicking on the layer in the Table of Contents and selecting Properties. On the Display tab, select Feature Exclusion > Restore All.
Get help from ArcGIS experts
Download the Esri Support App