Select to view content in your preferred language

how to change symbol (fill, color etc) on selected features only

1030
2
07-12-2012 09:12 AM
RinatSolorzano_Palero
Deactivated User
Hi everyone, i would like to know how to change the symbol properties on the selected features only, i want to fill it with linefillsymbol. Here's some code i've done but it doesnt work


Dim pFSel As IFeatureSelection
Set pFSel = pMap.Layer(0)

Dim pSelSet As ISelectionSet2
Dim pFeature As IFeature
Dim pFcursor As IFeatureCursor
Set pSelSet = pFSel.SelectionSet
pSelSet.Search Nothing, False, pFcursor
Set pFeature = pFcursor.NextFeature

Dim a As IFeatureRenderer
Dim pLSymbol As ILineFillSymbol
Set pLSymbol = New LineFillSymbol

Set a = pGFLayer.renderer
Set pLSymbol = a.SymbolByFeature(pFeature)

Dim pColor As IRgbColor
Set pColor = New RgbColor
pColor.RGB = RGB(255, 0, 0)
pLSymbol.color = pColor
pLSymbol.Separation = 7
pLSymbol.Angle = 70


'Dim padisplay As IDisplay
'Set padisplay = pMxDoc.ActiveView.ScreenDisplay
'padisplay.SetSymbol pLSymbol

'a.Draw pFcursor, esriDPSelection, padisplay, Nothing


pMxDoc.UpdateContents
pMxDoc.ActiveView.Refresh



thnks a lot!!
0 Kudos
2 Replies
PeterYurkosky1
Regular Contributor
IFeatureRenderer.SymbolByFeature returns a copy of a symbol. So all this code is doing is copying a renderer's symbol and then changing the copy. Even if it were "by-reference", you'd be modifying the symbol for all features that use that symbol, whether they're selected or not. That's surely not what you want.

I'd suggest looping over the cursor you got from the selection set and drawing the symbol directly via ISymbol.Draw.
0 Kudos
RinatSolorzano_Palero
Deactivated User
hi!, i've tried with the draw function from IFeatureRenderer using the cursor i have like this:


Dim pFSel As IFeatureSelection
Set pFSel = pMap.Layer(0)

Dim pSelSet As ISelectionSet2
Dim pFeature As IFeature
Dim pFcursor As IFeatureCursor
Set pSelSet = pFSel.SelectionSet
pSelSet.Search Nothing, False, pFcursor
Set pFeature = pFcursor.NextFeature

Dim a As IFeatureRenderer
Set a = pGFLayer.renderer
Dim pLSymbol As ILineFillSymbol
Set pLSymbol = New LineFillSymbol

Dim pColor As IRgbColor
Set pColor = New RgbColor
pColor.RGB = RGB(255, 0, 0)
pLSymbol.color = pColor
pLSymbol.Separation = 7
pLSymbol.Angle = 70

Dim padisplay As IDisplay
Set padisplay = pMxDoc.ActiveView.ScreenDisplay
padisplay.SetSymbol pLSymbol

a.Draw pFcursor, esriDPSelection, padisplay, Nothing


pMxDoc.UpdateContents
pMxDoc.ActiveView.Refresh


but i get an automation error, i'm not sure where's the mistake.... thanks for your help!!
0 Kudos