'Miles Hitchen Private Function GetLayerFromFeature(pFtr As IFeature) As IFeatureLayer 'Dim pFtr As IFeature Dim pFtrCls As IFeatureClass Dim pMxDoc As IMxDocument Dim pEnumLyr As IEnumLayer Dim pLyr As ILayer Dim pFtrLyr As IFeatureLayer Dim pObj As IObject ' Get the featureclass of the feature Set pObj = pFtr Set pFtrCls = pObj.Class ' Get a layer enumerator on the map Set pMxDoc = ThisDocument Set pEnumLyr = pMxDoc.FocusMap.Layers ' Loop through the layers until we find one that contains ' the same featureclass as the feature pEnumLyr.Reset Set pLyr = pEnumLyr.Next While Not pLyr Is Nothing If TypeOf pLyr Is IFeatureLayer Then Set pFtrLyr = pLyr If pFtrLyr.FeatureClass Is pFtrCls Then ' Found it! Set GetLayerFromFeature = pLyr Exit Function End If End If Set pLyr = pEnumLyr.Next Wend ' Not found so return Nothing Set GetLayerFromFeature = Nothing End Function
Dim doc As IMxDocument Set doc = ThisDocument 'will return all selected Dim enumFeature As IEnumFeature Set enumFeature = doc.FocusMap.FeatureSelection enumFeature.Reset 'Get the first feature Dim feature As IFeature Set feature = enumFeature.Next 'you can set additional selection options here Dim selectionEnvironment As ISelectionEnvironment Set selectionEnvironment = New selectionEnvironment doc.FocusMap.SelectByShape feature.Shape, selectionEnvironment, False doc.ActiveView.Refresh