OpenRoads Designer CONNECT Edition SDK Help

Create text favorite

The below code shows how to create new text favorite into current DGN.
//Required References
using Bentley.DgnPlatformNET;
using System.Linq;
 
public void CreateTextFavorite()
        {
            //Get active DgnFile and DgnModel
            Bentley.DgnPlatformNET.DgnFile activeDgnFile = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile();
            Bentley.DgnPlatformNET.DgnModel activeDgnModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();

            //Create new text favorite
            Bentley.DgnPlatformNET.DgnTextSnippet dgnTextSnippet = DgnTextSnippet.Create("Sample", activeDgnFile);
            dgnTextSnippet.SetDisplayName("SampleDisplayName");
            dgnTextSnippet.SetName("SampleName");

            //Get the first text style from the active DGN or create new if doesn't exist any
            Bentley.DgnPlatformNET.TextStyleCollection dgnTextStyles = activeDgnFile.GetTextStyles();
            Bentley.DgnPlatformNET.DgnTextStyle textStyle = null;
            if (dgnTextStyles.Count() > 0)
            {
                textStyle = dgnTextStyles.ElementAt(0);
            }
            else
            {
                textStyle = new DgnTextStyle("SampleTextStyle", activeDgnFile);
                textStyle.SetProperty(TextStyleProperty.Width, 400D);
                textStyle.SetProperty(TextStyleProperty.Height, 400D);
                textStyle.Add(activeDgnFile);
            }

            //Create new TextBlock to add to text favorite
            Bentley.DgnPlatformNET.TextBlock textBlock = new TextBlock(textStyle, activeDgnModel);
            textBlock.AppendText("Sample");
            dgnTextSnippet.SetSnippetText(textBlock);

            //Add to current DGN
            BentleyStatus status = dgnTextSnippet.Add(activeDgnFile);
        }

Output