各位老师打扰了,之前问过如何取得Text类型元素内容 https://communities.bentley.com/communities/other_communities/chinafirst/f/microstation-projectwise/190125/msce-c-text, 使用该方法可以获取到Text元素,但使用该方法处理TextNode类型元素时, TextElemHandler->InitTextString 会报错。
想知道该用什么方法获取TextNode的内容?
提前感谢
尝试一下如下方法,应该对Text和TextNode都统一有效的。
TextBlockPtr textBlockFromElement(ElementHandleCR eh) { ITextQueryCP textQuery = eh.GetITextQuery(); if (textQuery->IsTextElement(eh)) { return TextElemHandler::GetFirstTextPartValue(eh); } else return nullptr; } void extractTextString(ElementId myId) { ElementHandle eh(myId, ACTIVEMODEL); TextBlockPtr txtBlk = textBlockFromElement(eh); WString myStr = txtBlk->ToString(); mdlDialog_dmsgsPrint(myStr.GetWCharCP()); }
Answer Verified By: mkt
有效,谢谢符工!