I've encountered a strange problem while trying to populate an annotation feature class programmatically (ArcObjects, C#). As you can see in the image below, the characters in each text string seem to be stacking upon eachother, rather than laying-out horizontally as I would have expected.
I'm pulling in several values from MySQL (created by a different application), and those look fine in the debugger. I've tried using a mixture of unknown/projected coordinate system, as well a few different Element interfaces. If anyone has seen and conqured this issue before I would sure appreciate a push in the right direction.
Here's the relevant portion of my C#:
IFeature feature = featureClass.CreateFeature(); ITextElement textElement = new TextElementClass(); textElement.Text = textString; // value like: '183 IElement element = textElement as IElement; element.Geometry = pointGeom; // Point: x=2986785, y=629058 (feature as IAnnotationFeature2).Annotation = element; (feature as IAnnotationFeature2).AnnotationClassID = 0; (feature as IAnnotationFeature2).Status = annoStatus; // ESRI constant for 0, "placed" feature.Store();
And as promised, here's a look at the results I'm getting:
Per @Radar's advice I tried the following revision, but it still renders stacked/overlapped annotation text:
ISymbolCollectionElement scElement = new TextElementClass(); scElement.CharacterSpacing = 5; scElement.Geometry = pointGeom; scElement.Text = textString; (feature as IAnnotationFeature2).Annotation = scElement as IElement; (feat as IAnnotationFeature2).AnnotationClassID = 0; (feat as IAnnotationFeature2).Status = annoStatus;
Anyone have any additional insights?
Basically I'm trying to accomplish what @murdoch did in this "old" ArcScripts post (see his second entry). I reviewed his approach again and noticed he's using the IFormattedTextSymbol interface, so I tried that, yet I continue to experience the same problem with stacked/overlapping text in the placed annotations. Here's my latest thrust of C#:
IFeature feature = featureClass.CreateFeature(); IFontDisp font = new StdFontClass() as IFontDisp; font.Name = "Arial"; font.Bold = true; // font.Size = 30; // load in some reasonable default values.. IFormattedTextSymbol fmtTextSymb = new TextSymbolClass(); fmtTextSymb.Font = font; fmtTextSymb.Size = 30; fmtTextSymb.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; fmtTextSymb.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; fmtTextSymb.Angle = 0; fmtTextSymb.CharacterSpacing = 100; fmtTextSymb.CharacterWidth = 100; fmtTextSymb.FlipAngle = 90; fmtTextSymb.Leading = 0; fmtTextSymb.WordSpacing = 100; fmtTextSymb.Text = textString; // my special text value.. ITextElement textElement = new TextElementClass(); textElement.Symbol = fmtTextSymb; textElement.Text = textString; IElement element = textElement as IElement; element.Geometry = pt; (feature as IAnnotationFeature2).Annotation = element; feature.Store();
Anyone take issue with this? or have a favored-implementation? Here's what it looks like now; as you can see, the approach changed somewhat, but the results are the same:
On final analysis, the problem was not the code I used to create the individual annotations but as @Kirk Kuykendall revealed, the problem was how I initially created my AnnotationLayer with
IAnnotationLayerFactory.CreateAnnotationLayer(). I was submitting
null for the
IGraphicsLayerScale argument, assuming it would resolve to functional, if not ugly, default values. Apparently it does not. I created that object as follows, and it fixed my problem:
// Set the map scale and units the annos should be "cooked for". // To get ReferenceScale, open ArcMap and zoom to an appropriate level. // In the Standard toolbar, click the 1:N button (tip says "MapScale"). // It'll output something like 1:1,200. Drop the 1: and the comma // and that's the value you want for ReferenceScale. IGraphicsLayerScale graphicsLayerScale = new GraphicsLayerScaleClass(); graphicsLayerScale.ReferenceScale = 1200; graphicsLayerScale.Units = esriUnits.esriFeet; // this should agree with your proj