How to change text object "text" in C++

Hi all,

How can I change the inscription in the text?

		CRhinoDoc* doc = RhinoApp().ActiveDoc();
		const CRhinoText* Text_obj = Array_Text_obj[i];
		const ON_Plane Plane = Text_obj->Plane();
		const ON_DimStyle& DimStyle = Text_obj->GetEffectiveDimensionStyle(doc);
		const wchar_t* tmp_text = L"new text";

		ON_Text Text;
		CRhinoObjectAttributes  atts = Text_obj->Attributes();
		bool rc = Text.Create(tmp_text, &DimStyle, Plane);

		CRhinoText* new_Text_obj = new CRhinoText(atts);
		bool rcr = doc->ReplaceObject(CRhinoObjRef(Text_obj), new_Text_obj);

Can you help finding the error with it? Thanks in advance,

Hi @ccx07,

I’ve moved this to a new topic, since it doesn’t apply to the previous conversation.

– Dale

Hi Dale,
I’m trying to change the text object with “ReplaceObject”. I can’t do it yet.

Hi @ccx07,

The process of modifying text has gotten harder in Rhino 6 due to the use of rich text (RTF) and the fact that you can change fonts and font styles in a text string.

If text has a font set by an override for part of the text and you want to change the text content, you have to make RTF that includes the font override.

If the override is for the whole text, not a subsection, you could get the override style used by the current text and use ON_Annotation::SetOverrideDimensionStyle() to apply it to the new text.

You can tell if the font is overridden by using bool ON_DimStyle::IsFieldOverride(ON_DimStyle::field::font font)

And const ON_DimStyle& CRhinoAnnotation::GetEffectiveDimensionStyle(const CRhinoDoc* doc) to get the style, including overrides, from the current text.

Here is a sample of the latter:


– Dale

Hi Dale,
Everything works perfectly.


– Karlos