Monday, February 18, 2008

Setting Definition Queries for all layers

I just need to set definition query for all layers in one map. This script is just to demonstrate how to navigate layers in one map and the IFeatureLayerDefinition interface. I actually can write the "dropdown" box for PWP's feederID.

Sub SetDQ()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
Set pMxDoc = ThisDocumentSet
pMap = pMxDoc.ActiveView
Dim pFLayerDef As IFeatureLayerDefinition
Dim pEnumLayer As IEnumLayer
Set pEnumLayer = pMap.Layers
Set pLayer = pEnumLayer.Next
Do While Not pLayer Is Nothing
If TypeOf pLayer Is IFeatureLayer Then
Set pFLayerDef = pLayer
pFLayerDef.DefinitionExpression = "DELIVERY ='5'"
End If
Set pLayer = pEnumLayer.Next
Loop
pMxDoc.ActivatedView.Refresh
End Sub

No comments: