Create text object in center plane c++


       ON_Brep* brr = nullptr;
	CRhinoDoc* activeDoc = RhinoApp().ActiveDoc();
	if (activeDoc == nullptr)
		return nullptr;
	ON_wString st;
	st.Format(L"%d", 8);
	ON_wString face_name = L"Arial";
	const bool bBold = true;
	const bool bItalic = false;
	const ON_Font* font = ON_Font::GetManagedFont(face_name, bBold, bItalic);
	if (nullptr == font)
		return nullptr;
	ON_Plane pl_xz = activeDoc->ActiveView()->ActiveViewport().ConstructionPlane().m_plane;
	const ON_DimStyle& parent_dimstyle = activeDoc->m_dimstyle_table.CurrentDimStyle();
	ON_DimStyle dim_style = ON_DimStyle::CreateFromProperties(parent_dimstyle, ON::AnnotationType::Text, font, ON_UNSET_VALUE, 
		1.7, activeDoc->UnitSystem(), ON::TextVerticalAlignment::Middle, ON::TextHorizontalAlignment::Center);

	CRhinoText* rc = activeDoc->CreateTextObject(st, pl_xz, pl_xz.origin, &dim_style);
	if (rc == nullptr)
		return nullptr;
	const ON_Annotation* annotation = rc->Annotation();
	if (nullptr == annotation)
		return nullptr;
	const ON_DimStyle* dim_style1 = &annotation->DimensionStyle(
			true, true, activeDoc->m_dimstyle_table.CurrentDimStyleIndex())]);
	ON_SimpleArray<ON_Object*> output;
	bool rcc = RhinoCreateTextObjectGeometry(
		annotation, &RhinoApp().ActiveView()->Viewport().VP(), dim_style1, 1.0, true,
		activeDoc->AbsoluteTolerance(), 1.0, ON::object_type::extrusion_object, 0.4, 0.0, output);
	for (int i = 0; i < output.Count(); i++)
		if (nullptr == output[i])
			return nullptr;
		ON_Extrusion* ex = ON_Extrusion::Cast(output[i]);
		if (nullptr == ex)
			return nullptr;
		ON_Brep* brrr = ex->BrepForm(nullptr);
		if (brrr == nullptr)
			return nullptr;
		if (i == 0)
			brr = brrr;
			if (brrr->SolidOrientation() != 1)
		delete ex;
	if (brr == nullptr)
		return nullptr;

in my code, the text object will not in the center of plane, How can I Create it in center plane?

Hi @suc_kiet,

I have not looked at your code yet. But since your just creating extrusions, you can always transform them to wherever, based on the bounding box.

– Dale