I'm developing a tool in ArcGIS Pro related to annotation. In the tool, I'm creating feature-linked annotation for existing features and relating them together after the annotation is created. Currently, the Arcade label expression for the annotation doesn't automatically update the text string for the annotation after the relationship is created and I'm unsure of how to do this programmatically.
Is there a way to do this?
Solved! Go to Solution.
Feature-linked annotation text only updates if the base feature is updated of the annotation is edited directly. There are two approaches I could see for your case.
1) Update a field used in the expression and the event will fire an the annotation will update.
2) Or use calculate field on the TextString field of the annotation feature class with the label expression as the Arcade expression for the too.
Feature-linked annotation text only updates if the base feature is updated of the annotation is edited directly. There are two approaches I could see for your case.
1) Update a field used in the expression and the event will fire an the annotation will update.
2) Or use calculate field on the TextString field of the annotation feature class with the label expression as the Arcade expression for the too.
Hi again. I'm getting back to this and trying the second option to set the TextString field of the annotation feature class via a Calculate Field operation, but I'm not having much luck implementing this.
If I copy the label expression in the anno feature class directly onto the anno feature's TextString field (eg. "$feature.NAME"), Calculate Field fails because it's unable to find a 'NAME' field in the anno feature class, since the 'NAME' field is on the feature class that the annotation feature class is linked to.
Is there a way around this? Currently, I'm trying to explore options on the linked feature class itself (eg. QueryDisplayExpressions)
Thanks for the response!
I ended up using the first approach as I wanted to get something done quick, but I'll likely convert it into the second option instead to be more agnostic about which fields I need to update.
Here is what I had written at first for the first approach, for anyone else who may need code.
QueuedTask.Run(() =>
{
var editOperation = new EditOperation();
var fieldName = "name";
editOperation.Callback(context =>
{
relate.CreateRelationship(_sourceFeature, annoFeature);
ForceFeatureLinkedAnnoUpdate(_sourceFeature, _sourceAnnoFeatureLayer as AnnotationLayer, fieldName);
context.Invalidate(_sourceFeature);
}, _sourceFeatureLayer, _sourceAnnoFeatureLayer);
bool editResult = editOperation.Execute();
MapView.Active.Redraw(true);
});
private void ForceFeatureLinkedAnnoUpdate(Feature sourceFeature, AnnotationLayer annoLayer, string fieldName)
{
var fields = sourceFeature.GetFields().ToList();
if (sourceFeature.FindField(fieldName) > -1)
{
var currentValue = sourceFeature[fieldName];
sourceFeature[fieldName] = "LOADING ANNOTATION";
sourceFeature.Store();
sourceFeature[fieldName] = currentValue;
sourceFeature.Store();
}
}