[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
  • TextBlock

    I am trying to set the location of the text with the SetUserOrigin method, but the text is not created at that location

    Where is it created?  Is the actual location offset by the text justification CenterBaseline?

    Am I using the correct method?

    I don't see any other choice to SetUserOrigin!  I've been using it since CONNECT was introduced without a problem.

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

    There's some unneccessary work there.  Prefer EditElementHandle.AddToModel().  An element is displayed as soon as it's persisted to the DGN model.  That's been the case since MicroStation XM moved to DirectX many years ago.

    Lines and LineStrings

    create line element

    Prefer the LineHandler.CreateLineElement and LineStringHandler.CreateLineStringElement methods to MDL.

     
    Regards, Jon Summers
    LA Solutions

Reply
  • TextBlock

    I am trying to set the location of the text with the SetUserOrigin method, but the text is not created at that location

    Where is it created?  Is the actual location offset by the text justification CenterBaseline?

    Am I using the correct method?

    I don't see any other choice to SetUserOrigin!  I've been using it since CONNECT was introduced without a problem.

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

    There's some unneccessary work there.  Prefer EditElementHandle.AddToModel().  An element is displayed as soon as it's persisted to the DGN model.  That's been the case since MicroStation XM moved to DirectX many years ago.

    Lines and LineStrings

    create line element

    Prefer the LineHandler.CreateLineElement and LineStringHandler.CreateLineStringElement methods to MDL.

     
    Regards, Jon Summers
    LA Solutions

Children