MSCE SDK中取消了原来V8i下的文字操作来C函数mdlText_xxx,您需要重新学习类TextBlock,它能同时表达文字元素(TextElement)和文字节点元素(TextNodeElement)。
如下代码是一个典型的通过TextBlock创建一个MSCE下的文字的实例:
/*-------------------------------------------------------- | createText +-------------------------------------------------------*/ TextFieldPtr createField(DgnModelR model) { // "DgnElementSchema" and "ArcElement" are found from ...\MicroStation\ECSchemas\Dgn\DgnElementSchema.01.00.ecschema.xml DgnFileP pDgnFile = ISessionMgr::GetActiveDgnFile(); //SchemaInfo schemaInfo(ECN::SchemaKey(L"DgnElementSchema", 1, 0), *pDgnFile); SchemaInfo schemaInfo(ECN::SchemaKey(L"DgnCustomItemTypes_Architectural", 1, 0), *pDgnFile); DgnECManagerR ecMan = DgnECManager::GetManager(); ECN::ECSchemaPtr pSchema = ecMan.LocateSchemaInDgnFile(schemaInfo, ECN::SchemaMatchType::SCHEMAMATCHTYPE_LatestCompatible); if (pSchema == NULL) { mdlDialog_dmsgsPrint(L"Can't find identified schema"); return NULL; } //ECN::ECClassCR ecClass = *pSchema->GetClassCP(L"ArcElement"); //ECN::ECClassCR ecClass = *pSchema->GetClassCP(L"LineElement"); ECN::ECClassCR ecClass = *pSchema->GetClassCP(L"Doors"); ElementId elemId = 49064L; // An arc element id ElementHandle elem(elemId, &model); if (!elem.IsValid()) return NULL; DgnElementECInstancePtr pElemInst = ecMan.FindInstanceOnElement(elem, ecClass); //return TextField::CreateForElement(*pElemInst, L"Length", nullptr, model); //return TextField::CreateForElement(*pElemInst, L"TotalLength", nullptr, model); return TextField::CreateForElement(*pElemInst, L"Type", nullptr, model); } void createText(WCharCP unparsed) { DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP(); TextBlockPropertiesPtr pTBProp = TextBlockProperties::Create(*pActiveModel); pTBProp->SetIsViewIndependent(true); ParagraphPropertiesPtr pParaProp = ParagraphProperties::Create(*pActiveModel); //DgnTextStylePtr pTextStyle = DgnTextStyle::GetActive(); DgnTextStylePtr pTextStyle = DgnTextStyle::GetByName(L"5mm", StyleIteratorMode::ActiveFileAndLibraries); RunPropertiesPtr pRunProp = RunProperties::Create(*pTextStyle, *pActiveModel); //DPoint2d fontSize = DPoint2d::From(2000, 1000); //pRunProp->SetFontSize(fontSize); TextBlockPtr pTextBlock = TextBlock::Create(*pTBProp, *pParaProp, *pRunProp, *pActiveModel); pTextBlock->AppendText(L"This is a ViewIndependent text"); //TextFieldPtr pField = createField(*pActiveModel); //if (pField != NULL) // pTextBlock->AppendField(*pField); //pTextBlock->AppendParagraphBreak(); //pTextBlock->AppendText(L"Second Line"); EditElementHandle eeh; if (TEXTBLOCK_TO_ELEMENT_RESULT_Success == TextHandlerBase::CreateElement(eeh, nullptr, *pTextBlock)) { ElementPropertiesSetterPtr setter = ElementPropertiesSetter::Create(); setter->SetColor(3); // 3 -- Red setter->Apply(eeh); eeh.AddToModel(); } }
其中注释掉的一些行也都具有特定含义,取消注释能使程序功能更强大,比如,创建带有文字域(TextField)的文字、多行文字等。