[CONNECT U10 C++] Upgrading a call to V8i mdlText_create with a CONNECT TextBlock

I am replacing a call to mdlText_create with a TextBlock. I am trying to set the location of the text with the SetUserOrigin method, but the text is not created at that location.  Am I using the correct method or am I doing something else wrong?  I am including the code I use to create a text element and a line element. The line is created in the correct location but the text is not.

Private void text_test()
{
	                         
	Dpoint3d  ptTemp;
	ptTemp.x = 13307591.40;
	ptTemp.y = 994947.00;
	ptTemp.z = 291.70;
	
	//create text element
	TextBlockPropertiesPtr tbProps = TextBlockProperties::Create(*DgnTextStyle::GetActive(), *ISessionMgr::GetActiveDgnModelP());
	tbProps->SetIsViewIndependent(true);
	
	ParagraphPropertiesPtr paraProps = ParagraphProperties::Create(*DgnTextStyle::GetActive(), *ISessionMgr::GetActiveDgnModelP());
	paraProps->SetJustification(Bentley::DgnPlatform::TextElementJustification::CenterBaseline);

	RunPropertiesPtr runProps = RunProperties::Create(*DgnTextStyle::GetActive(), *ISessionMgr::GetActiveDgnModelP());
	
	TextBlockPtr textBlock = TextBlock::Create(*tbProps, *paraProps, *runProps, *ISessionMgr::GetActiveDgnModelP());
	textBlock->GetRunPropertiesForAddR().SetFontSize(DPoint2d::From(10.0,10.0));
	textBlock->SetUserOrigin(ptTemp);	
	textBlock->AppendText(L"test");

	EditElementHandle eeh;
	TextHandlerBase::CreateElement(eeh, NULL, *textBlock);
	MSElementP tmpElement;
	tmpElement = eeh.GetElementP();
	mdlElement_display(tmpElement, DgnPlatform::DRAW_MODE_Normal);
	mdlElement_add(tmpElement);


	//create line element
	Dpoint3d        testLine[2];
	testLine[0].x = ptTemp.x;
	testLine[0].y = ptTemp.y;
	testLine[0].z = ptTemp.z;

	testLine[1].x = ptTemp.x + 1.0;
	testLine[1].y = ptTemp.y;
	testLine[1].z = ptTemp.z;

	mdlLine_create(&element, NULL, testLine);
	mdlElement_display(&element, DgnPlatform::DRAW_MODE_Normal);
	mdlElement_add(&element);

}

Thanks for your help.

Warren

Parents
  • Please refer my below test code snippet. It can create text element in correct location running on MSCE-U13.

    	DgnModelP       pActiveModel = ISessionMgr::GetActiveDgnModelP();
    	TextBlockPropertiesPtr  pTBProp = TextBlockProperties::Create(*pActiveModel);
    	ParagraphPropertiesPtr  pParaProp = ParagraphProperties::Create(*pActiveModel);
    	pParaProp->SetJustification(TextElementJustification::LeftBaseline);
    	DgnTextStylePtr         pStyle = DgnTextStyle::GetActive();
    	RunPropertiesPtr        pRunProp = RunProperties::Create(*pStyle, *pActiveModel);
    
    	TextBlockPtr pTextBlock = TextBlock::Create(*pTBProp, *pParaProp, *pRunProp, *pActiveModel);
    	pTextBlock->SetUserOrigin(DPoint3d::From(10000, 10000, 0));
    	pTextBlock->AppendText(L"TestString");
    
    	EditElementHandle  eeh;
    	if (TEXTBLOCK_TO_ELEMENT_RESULT_Success ==
    		TextHandlerBase::CreateElement(eeh, nullptr, *pTextBlock))
    	{
    		eeh.AddToModel();
    	}



Reply
  • Please refer my below test code snippet. It can create text element in correct location running on MSCE-U13.

    	DgnModelP       pActiveModel = ISessionMgr::GetActiveDgnModelP();
    	TextBlockPropertiesPtr  pTBProp = TextBlockProperties::Create(*pActiveModel);
    	ParagraphPropertiesPtr  pParaProp = ParagraphProperties::Create(*pActiveModel);
    	pParaProp->SetJustification(TextElementJustification::LeftBaseline);
    	DgnTextStylePtr         pStyle = DgnTextStyle::GetActive();
    	RunPropertiesPtr        pRunProp = RunProperties::Create(*pStyle, *pActiveModel);
    
    	TextBlockPtr pTextBlock = TextBlock::Create(*pTBProp, *pParaProp, *pRunProp, *pActiveModel);
    	pTextBlock->SetUserOrigin(DPoint3d::From(10000, 10000, 0));
    	pTextBlock->AppendText(L"TestString");
    
    	EditElementHandle  eeh;
    	if (TEXTBLOCK_TO_ELEMENT_RESULT_Success ==
    		TextHandlerBase::CreateElement(eeh, nullptr, *pTextBlock))
    	{
    		eeh.AddToModel();
    	}



Children