AnsweredAssumed Answered

How can I create Text Anntation with given FontSize and Alignment ? 

Question asked by tkoka3 on Jan 26, 2018
Latest reply on Jan 26, 2018 by nchedzey-esristaff

Hi,

We are use 2.1 Arcgis Pro sdk to develope tools. How can I create Text Anntation with given FontSize and Alignment ? I can not set FontSize value (ex: 0,4) and Aligment value (ex: ArcGIS.Core.CIM.HorizontalAlignment.Center). I can do with second (update text annotation) operation after create with EditCompletedEvent like below :

 

 

var cimTextSymbol = symbol as CIMTextSymbol;
cimTextSymbol.HorizontalAlignment = ArcGIS.Core.CIM.HorizontalAlignment.Center;
cimTextSymbol.VerticalAlignment = ArcGIS.Core.CIM.VerticalAlignment.Center;

cimTextSymbol.SetSize(0.4);

 

How can I set values with the first operaton (create new text annotation) ?The code I'm using is below , here is also problem lines in bold text font :  

 

protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
{

bool result = await QueuedTask.Run(() =>
{

var annoLayer = MapView.Active.Map.FindLayers("ANNOTATIONLAYER").FirstOrDefault() as AnnotationLayer;
if (annoLayer == null)
return false;

var fc = annoLayer.GetFeatureClass() as ArcGIS.Core.Data.Mapping.AnnotationFeatureClass;
if (fc == null)
return false;

var cimDefinition = fc.GetDefinition() as ArcGIS.Core.Data.Mapping.AnnotationFeatureClassDefinition;
var labels = cimDefinition.GetLabelClassCollection();
var symbols = cimDefinition.GetSymbolCollection();

if ((labels.Count == 0) || (symbols.Count == 0))
return false;

var label = labels[0];
if (labels.Count > 1)
{
foreach (var LabelClass in labels)
{
if (LabelClass.Name == CurrentTemplate.Name)
{
label = LabelClass;
break;
}
}
}

var symbolName = label.TextSymbol.SymbolName;
int symbolID = -1;
if (!int.TryParse(symbolName, out symbolID))
{
foreach (var symbol in symbols)
{
if (symbol.Name == symbolName)
{
symbolID = symbol.ID;
break;
}
}
}
if (symbolID == -1)
return false;

Dictionary<string, object> values = new Dictionary<string, object>();
values.Add("SymbolID", symbolID);
values.Add("AnnotationClassID", label.ID);

int idxField = annoLayer.GetFeatureClass().GetDefinition().FindField("TextString");

values.Add("TextString", "Text");
values["SHAPE"] = geometry;


values["VerticalAlignment"] = ArcGIS.Core.CIM.VerticalAlignment.Center;     //NOT SET VALUE 
values["HorizontalAlignment"] = ArcGIS.Core.CIM.HorizontalAlignment.Center;   //NOT SET VALUE
values["FontSize"] = 0.4;    //NOT SET VALUE

var createOperation = new EditOperation();
createOperation.SelectNewFeatures = true;
createOperation.Create(annoLayer, values);

return createOperation.Execute();

});

return result;
}

 

 

Thanks .

Outcomes