Site Tools

Retrieving Annotation Text


Version: Rhino 4.0
Summary: Demonstrates how to retrieve the text string from an annotation text object using the Rhino 4.0 SDK.
Notice: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here.


If I have added annotation text to a model using Rhino's Text command or RhinoScript's AddText method, how can I retrieve the string using the SDK?


Rhino maintains annotation text in a CRhinoAnnotationText object, or MRhinoAnnotationText in .NET languages. You can retrieve the text string as follows:


Public Overrides Function RunCommand(ByVal context As RMA.Rhino.IRhinoCommandContext) _ 
        As RMA.Rhino.IRhinoCommand.result
  Dim go As New MRhinoGetObject
  go.SetCommandPrompt("Select annotation text")
  go.GetObjects(1, 1)
  If (go.CommandResult() <> IRhinoCommand.result.success) Then
    Return go.CommandResult()
  End If
  Dim annotation_obj As IRhinoAnnotationText = MRhinoAnnotationText.ConstCast(go.Object(0).Object())
  If (annotation_obj Is Nothing) Then
    RhUtil.RhinoApp().Print("Not an annotation text object." + vbCrLf)
  End If
  Dim str As String = annotation_obj.String()
  RhUtil.RhinoApp().Print(String.Format("Annotation text = {0}" + vbCrLf, str))
  Return IRhinoCommand.result.success
End Function
developer/sdksamples/gettext.txt ยท Last modified: 2020/08/14 (external edit)