Product(s): | OpenBuildings Designer | ||
Version(s): | CONNECT Edition | ||
Area: | SDK |
Microsoft no longer includes the Aerial Unicode MS font with Outlook, a font that we've been using for some time. We have identified a suitable replacement and method to automatically update the font, however the Propertyhander in the API requires a "FontName" index. When looked at on my system the numbers are:
Aerial Unicode MS - 1025
Segoe UI Symbol - 1215
Are these fonts indexed at the system level, in OpenBuildings Designer or MicroStation? Also, are they the same on all machines, or will this vary machine to machine? If so, is there a way to use the font name instead? Here is a snip-it of the existing code:
BCOM.ElementScanCriteria scanCriteria = new BCOM.ElementScanCriteriaClass();
scanCriteria.ExcludeNonGraphical();
scanCriteria.ExcludeAllLevels();
scanCriteria.ExcludeAllTypes();
scanCriteria.IncludeLevel(ToolCommon.MicroStation.GetLevel("F-PROT-~~~~-~~~~"));
scanCriteria.IncludeType(MsdElementType.Text);
scanCriteria.IncludeType(MsdElementType.TextNode);
BCOM.ElementEnumerator ee = ToolCommon.MicroStation.Application.ActiveModelReference.Scan(scanCriteria);
while (ee.MoveNext())
{
BCOM.Element elementFound = ee.Current;
BCOM.PropertyHandler propertyHandler = ToolCommon.MicroStation.Application.CreatePropertyHandler(elementFound);
// Setting up Access String
propertyHandler.SelectByAccessString("FontName");
// Getting Value of Current
///// System.Diagnostics.Debug.Print(propertyHandler.GetValue().ToString());
// Current font Aerial Unicode MS returns indexed value of 1024
// Proposed font opton Segoe UI Symbol retunrs a indexed value of 1215
if (propertyHandler.GetValue().ToString() == "1024")
{
propertyHandler.SetValue(1215);
propertyHandler.SelectByAccessString("TextColor");
propertyHandler.SetValue(7);
}
With the exception of RSC based fonts, font IDs are are file specific as outlined in this wiki.
While you can determine a font’s ID number for the current DGN file, using font name is easier and more reliable. Below is sample code for changing fonts by name. Note that the font is part of the Text Style, so color and other properties can be changed in the same way.
public static void FontTest()
{
BCOM.ElementScanCriteria scanCriteria = new BCOM.ElementScanCriteriaClass();
scanCriteria.ExcludeNonGraphical();
scanCriteria.ExcludeAllTypes();
scanCriteria.IncludeType(BCOM.MsdElementType.Text);
scanCriteria.IncludeType(BCOM.MsdElementType.TextNode);
// May need to use MicroStation.Application.ActiveModelReference …
BCOM.ElementEnumerator ee = Application.ActiveModelReference.Scan(scanCriteria);
while (ee.MoveNext())
{
BCOM.Element elementFound = ee.Current;
if (elementFound.IsTextElement())
{
SetTextElementFont(elementFound.AsTextElement());
}
else if (elementFound.IsTextNodeElement())
{
// A text node is a collection of text elements
BCOM.ElementEnumerator tnee = elementFound.AsTextNodeElement().GetSubElements();
while (tnee.MoveNext())
SetTextElementFont(tnee.Current.AsTextElement());
}
}
}
public static void SetTextElementFont(BCOM.TextElement textElement)
{
// May need to use MicroStation.Application.ActiveDesignFile …
BCOM.Font font = Application.ActiveDesignFile.Fonts.Find(BCOM.MsdFontType.WindowsTrueType, "Courier New");
int color = 7;
textElement.TextStyle.Font = font;
textElement.TextStyle.Color = color;
textElement.Rewrite();
}