I am trying to create a text field that displays the origin elevation of its host element.
I can accomplish this 2 different ways
1) I create a placeholder text element, add it to the model, then create a new text element containing the text field.. I can then replace the placeholder element with the new text element.
2) I create a text field using DgnPlatform::TextField::CreatePlaceHolderForCell, I then create a cell element that hosts my text element\field.
Number 1 works, however, I would like to not have to add the element to the model during its construction
Number 2 works, however, the text field initially says "Text Origin" until I click in any view once.
Does anyone else have any ideas \ solutions?
Thanks,
Maury
Video:
https://certainty3d-my.sharepoint.com/:v:/g/personal/mauricio_terneus_topodot_com/EfRtPr1VCTtNn0Ihk1qDIIkBjGdZjokRBouVbZORc94ySw?e=yhykqJ
Creating Text Field:
DgnPlatform::TextFieldPtr CreateElevationField(DgnModelR model) { // "DgnElementSchema" are found from ...\MicroStation\ECSchemas\Dgn\DgnElementSchema.01.00.ecschema.xml DgnECManagerR ecMan = DgnPlatform::DgnECManager::GetManager(); DgnFileP pDgnFile = ISessionMgr::GetActiveDgnFile(); DgnPlatform::SchemaInfo schemaInfo(ECN::SchemaKey(L"DgnElementSchema", 1, 0), *pDgnFile); ECN::ECSchemaPtr pSchema = ecMan.LocateSchemaInDgnFile(schemaInfo, ECN::SchemaMatchType::SCHEMAMATCHTYPE_LatestCompatible); if (pSchema == NULL) return nullptr; ECN::ECClassCR ecClass = *pSchema->GetClassCP(L"TextElement"); ECN::ECPropertyP property = ecClass.GetPropertyP("Origin", true); IDgnECTypeAdapterR adapter = DgnPlatform::IDgnECTypeAdapter::GetForProperty(*property); ECN::IECInstancePtr formatter = adapter.CreateDefaultFormatter(true); ECN::ECValue coordinateValue { 4}; // Only display Z formatter->SetValue(L"Coordinates", coordinateValue); //MstnPropertyFormatter.01.00.ecschema.xml return DgnPlatform::TextField::CreatePlaceHolderForCell(*property, formatter.GetCR(), model);;// DgnPlatform::TextField::CreateForElement(*pElemInst, L"Origin", formatter.GetCR(), model); }
Creating Text Element:
DgnModelP activeDgnModelP = ISessionMgr::GetActiveDgnModelP(); DgnPlatform::TextBlockPropertiesPtr tbProps = DgnPlatform::TextBlockProperties::Create(*activeDgnModelP); DgnPlatform::ParagraphPropertiesPtr paraProps = DgnPlatform::ParagraphProperties::Create(*activeDgnModelP); DgnPlatform::RunPropertiesPtr runProps = DgnPlatform::RunProperties::Create(*DgnPlatform::DgnTextStyle::GetActive(), *activeDgnModelP); tbProps->SetIsViewIndependent(true); paraProps->SetJustification(alignment); UInt32 textColorIndex; mdlColor_rawColorFromRGBColor(&textColorIndex, &color, ACTIVEMODEL); runProps->SetColor(textColorIndex); runProps->SetFontSize(fontSizeScaled); DgnPlatform::TextBlockPtr textBlock = DgnPlatform::TextBlock::Create(*tbProps, *paraProps, *runProps, *activeDgnModelP); DgnPlatform::TextFieldPtr pField = CreateElevationField(*activeDgnModelP); if (pField != NULL) textBlock->AppendField(*pField); textBlock->SetProperties(*tbProps); textBlock->SetUserOrigin(originUor); textBlock->SetOrientation(orientation); DgnPlatform::EditElementHandle eeh; DgnPlatform::TextHandlerBase::CreateElement(eeh, NULL, *textBlock);
Creating Cells:
if (childElements.empty()) return false; DgnModelRefP modelRef = ACTIVEMODEL; DgnPlatform::NormalCellHeaderHandler::CreateCellElement(eeh, name, originUor, RotMatrix::FromIdentity(), true, *modelRef); for (const DgnPlatform::ElementHandle& eh : childElements) { DgnPlatform::EditElementHandle eeh2(eh, false); DgnPlatform::NormalCellHeaderHandler::AddChildElement(eeh, eeh2); } DgnPlatform::NormalCellHeaderHandler::AddChildComplete(eeh);
Hi Maury,
At some point after TextHandlerBase::CreateElement, do you call eeh.AddToModel(). Could you try adding right after (if not shown or needing later) and see if that helps?
Thank you,Bob
Hi Robert,
It is not shown above since I had to rip the code out of a few places, but...
For the first method where I end up with a Text Element, I call AddToModel once to place the placeholder, and then ReplaceInModel to update the placeholder with the Text field.
In the 2nd method, I take the eeh and add it to a cell using the code above. Then I call AddToModel on the cell element.
I should not need to call it on the text Element in this case, correct?
Maury,
Try inserting a call to DependencyManager::ProcessAffected() after your AddToModel().
That is what happens when you click in the view.
It tells the dependency system to update all dependent elements (including the field in the text element you just created).
Answer Verified By: Maury
Thanks Paul. That worked