Select to view content in your preferred language

How do I change color of annotation through code?

1156
2
05-26-2010 01:33 PM
AshalaPalaniuk
Emerging Contributor
Hello Fellow-Forum-ers!

I have an application that loads a whole bunch of layers, some of which are SDE annotation layers.  I cannot figure out how to change the symbology of the annotation, namely color (but also size).  For simplicity sake and for testing I am working with only one layer in a new, separate document and have included my code below for bringing in the annotation layer.  While this differs from my actual application this serves its purpose for trouble-shooting. 

So my question is - how do I change the color that this annotation layer loads in?

Any help pointing me in the right direction would be appreicated as I am definitely stumped.  Thanks so much!


Private Function MxDocument_OPENDOCUMENT() As Boolean

Dim pPropset As IPropertySet
Set pPropset = New PropertySet
With pPropset
.SetProperty "Server", "*****"
.SetProperty "Instance", "*****"
.SetProperty "user", "*****"
.SetProperty "password", "*****"
.SetProperty "version", "*****"
End With

Dim pworkspacename As IWorkspaceName
Set pworkspacename = New WorkspaceName
pworkspacename.WorkspaceFactoryProgID = "esricore.SdeWorkspaceFactory"
pworkspacename.ConnectionProperties = pPropset

Dim pdatasetName As IDatasetName
Set pdatasetName = New FeatureClassName

pdatasetName.Name = "chwksde.dbo.SS_SansymAnno"
Set pdatasetName.WorkspaceName = pworkspacename

Dim pname As IName
Set pname = pdatasetName

Dim ptable As ITable
Set ptable = pname.Open

Dim pfeatclass As IDataset
Set pfeatclass = ptable

Dim pfeatlay As IFeatureLayer
Dim pFDOGraphicsLayerFactory As IFDOGraphicsLayerFactory
Set pFDOGraphicsLayerFactory = New FDOGraphicsLayerFactory
Set pfeatlay = pFDOGraphicsLayerFactory.OpenGraphicsLayer(pfeatclass.Workspace, Nothing, "chwksde.dbo.SS_SansymAnno")

pfeatlay.Name = pfeatclass.Name

Dim pmap As IMap
Dim pmxdoc As IMxDocument

Set pmxdoc = ThisDocument
Set pmap = pmxdoc.ActiveView

pmap.AddLayer pfeatlay

Dim pav As IActiveView
Set pav = pmap

pav.Refresh

End Function
0 Kudos
2 Replies
AshalaPalaniuk
Emerging Contributor
It figures that after toiling over it for ages I come to my conclusion shortly after I post it!  Here is the solution for anyone that's wondering.  I pieced part of this from a previous post solution that I found by Babak - many thanks to you!

Private Function mxDocument_opendocument() As Boolean

Dim pPropset As IPropertySet
Set pPropset = New PropertySet
With pPropset
.SetProperty "Server", "*****"
.SetProperty "Instance", "*****"
.SetProperty "user", "*****"
.SetProperty "password", "*****"
.SetProperty "version", "*****"
End With

Dim pworkSpacename As IWorkspaceName
Set pworkSpacename = New WorkspaceName
pworkSpacename.WorkspaceFactoryProgID = "esricore.SdeWorkspaceFactory"
pworkSpacename.ConnectionProperties = pPropset

Dim pdatasetName As IDatasetName
Set pdatasetName = New FeatureClassName

pdatasetName.Name = "chwksde.dbo.SS_SansymAnno"
Set pdatasetName.WorkspaceName = pworkSpacename

Dim pname As IName
Set pname = pdatasetName

Dim ptable As ITable
Set ptable = pname.Open

Dim pfeatclass As IDataset
Set pfeatclass = ptable

Dim pAnnotationLayer As IAnnotationLayer
Dim pFDOGraphicsLayerFactory As IFDOGraphicsLayerFactory
Set pFDOGraphicsLayerFactory = New FDOGraphicsLayerFactory
Dim player As ILayer
Set pAnnotationLayer = player
Set pAnnotationLayer = pFDOGraphicsLayerFactory.OpenGraphicsLayer(pfeatclass.Workspace, Nothing, "chwksde.dbo.SS_SansymAnno")

Dim pRGBColorAnno As IRgbColor
Set pRGBColorAnno = New RgbColor

With pRGBColorAnno
    .Red = 255
    .Green = 0
    .Blue = 0
End With

Dim pFDOGraphicsLayer As IFDOGraphicsLayer
Dim pFDOGraphicsRead As IFDOGraphicsLayerRead
Dim symbolSubstitution As ISymbolSubstitution

Set pFDOGraphicsLayer = pAnnotationLayer
Set pFDOGraphicsRead = pFDOGraphicsLayer
Set symbolSubstitution = pFDOGraphicsRead

symbolSubstitution.SubstituteType = esriSymbolSubstituteColor
Set symbolSubstitution.MassColor = pRGBColorAnno
Set symbolSubstitution.InlineColor = pRGBColorAnno

Dim pmap As IMap
Dim pmxdoc As IMxDocument

Set pmxdoc = ThisDocument
Set pmap = pmxdoc.ActiveView

pmap.AddLayer pAnnotationLayer

Dim pav As IActiveView
Set pav = pmap

pav.Refresh


End Function
0 Kudos
AiminGong
Emerging Contributor

How to start a editing and update the colour (all other apsects like font size etc. shoud be remain unchnaged ) of a annotation feature class with some codes?

0 Kudos