[Connect Update 16 C#] Get Datafield from Textblock

There are a few examples of identifying EDF in a single textblock using the C++ api, i was hoping someone has done that in the .net api, or could point me in the right direction. I am able to Get Textblock, and create a caret, but how do I get a Run from a caret? Looks like there's Caret.MoveToNextRun, but that doesn't seem to return a run, and Caret.PreviousCharacter and Caret.NextCharacter returns just Char, which isn't going to help me identify if its an EDF or not. Is there another way of stepping through each part of a textblock?

Thanks.

Parents
  • I wrote a test code as below to get EDF from text element. It uses several new text related classes, such as ParagraphRange, ParagraphIterator and RunIterator.

    private static void GetEDF()
            {
                ulong id = 1193;
                DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
                Element elem = dgnModel.FindElementById(new ElementId(ref id));
                TextQuery txtQuery = TextQuery.GetAsTextQuery(elem);
                TextQueryOptions options = new TextQueryOptions();
                TextPartIdCollection txtParts = txtQuery.GetTextPartIds(options);
                TextBlock txtBlk = txtQuery.GetTextPart(txtParts[0]);
                ParagraphRange paraRng = new ParagraphRange(txtBlk);
                ParagraphIterator paraIter = paraRng.GetParagraphIterator();
                while (paraIter.MoveNext())
                {
                    RunIterator runIter = paraIter.GetRunIterator();
                    while (runIter.MoveNext())
                    {
                        Run run = runIter.Current;
                        EdfCharStream edf = run as EdfCharStream;
                        bool isEdf = (edf == null) ? false : true;
                        MessageCenter.Instance.ShowInfoMessage(run.ToString() + ", isEdf =" + isEdf.ToString(), null, false);
                    }
                }
            }

    My test text is as below:

    Output in message center is as below:

    I also just write a wiki to discuss what is TextPart as below. The article is in Chinese but I believe google can easily translate it into EnglishYum.

    关于TextBlock中的TextPart



  • That looks usable! Thanks  , so a follow up question on this, using the ParagraphIterator and RunIterator should only be used for understanding the contents of the textblock but not for updating, right? If i need to update part of the EDF i would need to use the TextBlock.Insert.... methods? Is that right?

Reply Children
No Data