Symbology from RGB in attribute table

Discussion created by rfoscarini on Jan 6, 2012
Latest reply on Sep 13, 2016 by Didit1
Hi everyone...

I found this code

'Modified ESRI Developer Sample
Sub SymbolizeFeaturesByRGBAttributes()

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap

Dim pLayer As IGeoFeatureLayer
Set pLayer = pMap.Layer(0)

Dim pFeatClass As IFeatureClass
Set pFeatClass = pLayer.FeatureClass
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter
Dim pFeatCursor As IFeatureCursor
Set pFeatCursor = pFeatClass.Search(pQueryFilter, False)

Dim pRender As IUniqueValueRenderer
Set pRender = New UniqueValueRenderer

pRender.FieldCount = 3
pRender.Field(0) = "RED"
pRender.Field(1) = "GREEN"
pRender.Field(2) = "BLUE"
pRender.FieldDelimiter = ","
pRender.UseDefaultSymbol = False

Dim n As Integer
n = pFeatClass.FeatureCount(pQueryFilter)
Dim i As Integer
i = 0

Dim ValFound As Boolean
Dim NoValFound As Boolean
Dim uh As Integer
Dim pFields As IFields
Dim iRedField As Integer
Dim iGreenField As Integer
Dim iBlueField As Integer

Set pFields = pFeatCursor.Fields
iRedField = pFields.FindField("RED")
iGreenField = pFields.FindField("GREEN")
iBlueField = pFields.FindField("BLUE")

Do Until i = n

Dim pFeat As IFeature
Set pFeat = pFeatCursor.NextFeature

Dim w As String
w = pFeat.value(iRedField) & "," & pFeat.value(iGreenField) & "," & pFeat.value(iBlueField)
ValFound = False

For uh = 0 To (pRender.ValueCount - 1)
If pRender.value(uh) = w Then
NoValFound = True
Exit For
End If
Next uh
If Not ValFound Then
Dim x As String
Dim y As String
Dim z As String
x = pFeat.value(iRedField)
y = pFeat.value(iGreenField)
z = pFeat.value(iBlueField)

Dim pColor As IRgbColor
Set pColor = New RgbColor
pColor.red = x
pColor.green = y
pColor.blue = z

Dim symx As ISimpleFillSymbol
Set symx = New SimpleFillSymbol
symx.Outline.Width = 0.5
symx.style = esriSFSSolid
symx.Color = pColor

pRender.AddValue w, "", symx
pRender.Symbol(w) = symx
End If
i = i + 1

Set pLayer.Renderer = pRender

'** This makes the layer properties symbology tab show
'** show the correct interface.
Dim hx As IRendererPropertyPage
Set hx = New CombiUniqueValuePropertyPage
pLayer.RendererPropertyPageClassID = hx.ClassID

'** Refresh the TOC

'** Draw the map

End Sub

It was posted by Michael Knight here: http://forums.esri.com/Thread.asp?c=93&f=1730&t=187747&mc=8#555759

I want to know if is there anyone who can translate it to python, so we can use it in arcgis10...

What i want is to symbolize my polygons feature with the RGB value in the attribute table... It would take a lot of time setting one by one...