I'm wondering if someone has or knows where a tool is to edit the 'Display Expression' of a Layer, or more specifically, a TableView, in ArcGIS Desktop. I know that it can't be accessed with Python, but it should be editable with ArcObjects. But this isn't something I know how to do yet.
I'm using a Python Add-in to add a Layer into ArcMAP which has a relate with a couple TableViews that I add at the same time. The trouble is that it always resets the field that is displayed in the identify window to something unhelpful.
Thanks for any suggestions.
Answer
You will need to use ArcObjects. You are looking for the IDisplayExpressionProperties interface. It is obtained from IDisplayString, which in turn is obtained from IFeatureLayer. Here you will find a fantastic little snippet of code provided by patrick that does the trick:
public void annotateLayer(ILayer thisLayer, String geocode, double minScale, double maxScale, bool annotationsOn, bool showMapTips, RgbColor annotationLabelColor)
{
IGeoFeatureLayer geoLayer = thisLayer as IGeoFeatureLayer;
if (geoLayer != null)
{
geoLayer.DisplayAnnotation = annotationsOn;
IAnnotateLayerPropertiesCollection propertiesColl = geoLayer.AnnotationProperties;
IAnnotateLayerProperties labelEngineProperties = new LabelEngineLayerProperties() as IAnnotateLayerProperties;
IElementCollection placedElements = new ElementCollectionClass();
IElementCollection unplacedElements = new ElementCollectionClass();
propertiesColl.QueryItem(0, out labelEngineProperties, out placedElements, out unplacedElements);
ILabelEngineLayerProperties lpLabelEngine = labelEngineProperties as ILabelEngineLayerProperties;
lpLabelEngine.Expression = geocode;
lpLabelEngine.Symbol.Color = annotationLabelColor;
labelEngineProperties.AnnotationMinimumScale = minScale;
labelEngineProperties.AnnotationMaximumScale = maxScale;
IFeatureLayer thisFeatureLayer = thisLayer as IFeatureLayer;
IDisplayString displayString = thisFeatureLayer as IDisplayString;
IDisplayExpressionProperties properties = displayString.ExpressionProperties;
properties.Expression = geocode; //example: "[OWNER_NAME] & vbnewline & \"$\" & [TAX_VALUE]";
thisFeatureLayer.ShowTips = showMapTips;
}
}
Note the variable "geocode" which is stored in properties.Expression. You can specify a single column name or a combination of different column names, or even a single variable.
No comments:
Post a Comment