Hello,
The function below should describe my question quite well.
I am running Microstation 10.16.03.11.
Best regards
// using Bentley.DgnPlatformNET; private static void ReplaceVisibleTagsWithText() { var visibleTags = Session.Instance.GetActiveDgnModel().GetElements().OfType<TagElement>().Where(t => t.IsInvisible == false); foreach (var tag in visibleTags) { if (tag.TagName.Equals("PartNumber")) { continue; } else { tag.GetTransformOrigin(out DPoint3d tagOrigin); tag.GetOrientation(out DMatrix3d tagOrientation); // This is where I want to get the height, width, justification and font. Not sure if TextStyle or something similar can be used to get the formatting. // These properties would be passed to the function below. Utilities.ElementHelper.PlaceText(tag.GetTagValue().ToString(), tagOrigin, tagOrientation); } } }
Hi Petter,
tags, because so old (MicroStation 95?), does not offer any formatting options. The displayed tags are similar to text elements, because it uses active style (Text Style: (none)) when it is created. Manually the tags can be changed using Change Text Attributes tool, so I guess in code it should be similar: To apply new text style.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Petter Vennberg said:How do I get the formatting for a visible tag using C#?
Take a look at the TextBlock class. According to DgnPlatformNET help: In the TextBlock DOM, this is the master object that represents a piece of text as a whole, and is the primary high-level object used to deal with multi-line, formatted text (and is also generally recommended for any text, regardless of complexity). I believe that the TextBlock is intended to help with tags as well as normal text elements.
TextBlock
Regards, Jon Summers LA Solutions
Thanks for the pointers.
I ended up doing this.
private static void ReplaceVisibleTagsWithText() { var visibleTags = Session.Instance.GetActiveDgnModel().GetElements().OfType<TagElement>().Where(t => t.IsInvisible == false); foreach (var tag in visibleTags) { if (tag.TagName.Equals("PartNumber")) { continue; } else { TextQueryOptions textQueryOptions = new TextQueryOptions { ShouldIncludeEmptyParts = false, ShouldRequireFieldSupport = false }; var textPartIds = tag.GetTextPartIds(textQueryOptions); var tagTextBlock = tag.GetTextPart(textPartIds[0]); tag.GetTransformOrigin(out DPoint3d tagOrigin); tag.GetOrientation(out DMatrix3d tagOrientation); var textBlock = new TextBlock(tagTextBlock.GetProperties(), tagTextBlock.GetParagraphPropertiesForAdd(), tagTextBlock.GetRunPropertiesForAdd(), Session.Instance.GetActiveDgnModel()); textBlock.AppendText(tag.GetTagValue().ToString()); textBlock.SetUserOrigin(tagOrigin); textBlock.SetOrientation(tagOrientation); var textElement = TextHandlerBase.CreateElement(null, textBlock); textElement.AddToModel(); } } }
Answer Verified By: Petter Vennberg