About CRhinoAnnotationText in V6

My code in V5 as following, but I don’t know how to convert that to V6, because there is no CRhinoAnnotationText on V6.

In the CRhinoAnnotationText* text_object
I want to SetAnnotation, SetTextHeight, SetString, SetPlane, SetJustification and SetFontIndex.

//my code in v5

CRhinoAnnotationText* CCommandSample::AddAnnotationText(const ON_3dPoint& pt, const wchar_t* text, double height, const wchar_t* font, int style, double rotate, ON_Annotation2::eTextJustification Justification)
  {
    CRhinoAnnotationText* text_object = new CRhinoAnnotationText;

    ON_wString wText(text);
    if (wText.IsEmpty())
      return text_object;

    if (height <= 0)
      height = 1.0;

    ON_wString wFont(font);
    if (wFont.IsEmpty())
      wFont = L"Arial";

    if (style < 0 || style > 3)
      style = 0;

    ON_Plane plane = ON_xy_plane;
    plane.SetOrigin(pt);
    plane.Rotate(rotate, ON_zaxis);

    ON_TextEntity2* text_entity = new ON_TextEntity2;
    text_object->SetAnnotation(*text_entity);
    text_object->SetTextHeight(height);
    text_object->SetString(wText);
    text_object->SetPlane(plane);
    text_object->SetJustification(Justification);
    int idx = ::RhinoApp().ActiveDoc()->m_font_table.FindOrCreateFont(wFont, style & 1, style & 2);
    text_object->SetFontIndex(idx);

    return text_object;
  }

Hi @angelwang,

One of the biggest changes to Rhino 6 is in the area of annotations. Here is an overview of what’s new:

http://developer.rhino3d.com/guides/cpp/annotation-objects/

And here is an example of using the new SDK classes:

https://github.com/mcneel/rhino-developer-samples/blob/6/cpp/SampleCommands/cmdSampleAddText.cpp

Let me know if you have questions.

– Dale

@dale
Thanks for your answer.

Now I have another question.
How to explode the object of CRhinoText to curves?
Before there is explode function in CRhinoAnnotationText, but I can’t find this kind function in V6.

Hi @angelwang,

Use RhinoGetTextOutlines. See rhinoSdkUtilities.h for details.

– Dale

Hi @dale

How to get user string from CRhinoText?

How about this?

CRhinoObjRef object_ref = ....;

const CRhinoText* obj = CRhinoText::Cast(object_ref.Object());
if (nullptr != obj)
{
  CRhinoDoc* doc = obj->Document();
  if (nullptr != doc)
  {
    const ON_DimStyle& dimstyle = obj->GetEffectiveDimensionStyle(doc);
    const ON_Text* text_obj = obj->TextObject(&dimstyle);
    if (nullptr != text_obj)
    {
      ON_wString value = text_obj->PlainText();
      // TODO...
    }
  }
}

– Dale

Hi @dale

Thank you very much. it works fine.