[MSCE C#]How can i get the DgnTextStyle?

I'd like to get a DgnTextStyle  from an  TextElement ,but that returns  IsNull().

TextElement txtElement = dgnmodel.FindElementById(el.ElementId) as TextElement;
DgnTextStyle textstyle = DgnTextStyle.GetSettings(dgnfile);
DgnTextStyle dgntext = DgnTextStyle.GetById(txtElement.ElementId,dgnfile);

  • DgnTextStyle dgntext = DgnTextStyle.GetById(txtElement.ElementId,dgnfile);

    GetById wants the ID of the text style, not the ID of the text element.  The documentation is confusing because it shows the data type of the argument as ElementId — but that's just an alias for a 64-bit unsigned integer.

    Look up a text style in the DGN file collection …

    DgnFile dgnFile = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile();
    DgnTextStyle style = DgnTextStyle::GetByName ("Shaopu.Cao", dgnFile);
    // use style.Id

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Shaopu.Cao 

  • TextElement txtEle = dgnmodel.FindElementById(el.ElementId) as TextElement;
    ElementPropertiesGetter txtgetter = new ElementPropertiesGetter(txtEle);
    TextPartIdCollection textParts = txtEle.GetTextPartIds(new TextQueryOptions());
    TextBlock txtBlock = txtEle.GetTextPart(textParts[0]);
    ulong id = txtBlock.GetProperties().TextStyleId;
    ElementId txtId = new ElementId(ref id);
    DgnTextStyle txtStyle = DgnTextStyle.GetById(txtId, Session.Instance.GetActiveDgnFile());
    textdescript = txtStyle.Name;

    Thank you very much for your answer. The Bentley technical support teacher in China gave the answer above. I passed the test here. Thank you. The document really puzzles me.