[Connect C++] Proper use of DgnPlatform::TextField::CreatePlaceHolderForCell

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);

Parents Reply Children