Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:gettext [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Retrieving Annotation Text =====
 +
 +===== C# =====
 +<code c#>
 +public class ReadDimensionTextCommand : Rhino.Commands.Command
 +{
 +  public override string EnglishName
 +  {
 +    get { return "​csReadDimensionText";​ }
 +  }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    var go = new GetObject();​
 +    go.SetCommandPrompt("​Select annotation"​);​
 +    go.GeometryFilter = ObjectType.Annotation;​
 +    go.Get();
 +    if (go.CommandResult() != Result.Success) ​
 +      return Result.Failure;​
 +    var annotation = go.Object(0).Object() as AnnotationObjectBase;​
 +    if (annotation == null)
 +      return Result.Failure;​
 +
 +    RhinoApp.WriteLine("​Annotation text = {0}", annotation.DisplayText);​
 +
 +    return Result.Success;​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class ReadDimensionTextCommand
 +  Inherits Rhino.Commands.Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbReadDimensionText"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim go = New GetObject()
 +    go.SetCommandPrompt("​Select annotation"​)
 +    go.GeometryFilter = ObjectType.Annotation
 +    go.[Get]()
 +    If go.CommandResult() <> Result.Success Then
 +      Return Result.Failure
 +    End If
 +    Dim annotation = TryCast(go.[Object](0).[Object](),​ AnnotationObjectBase)
 +    If annotation Is Nothing Then
 +      Return Result.Failure
 +    End If
 +
 +    RhinoApp.WriteLine("​Annotation text = {0}", annotation.DisplayText)
 +
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.DocObjects import *
 +from Rhino.Commands import *
 +from Rhino.Input.Custom import *
 +import rhinoscriptsyntax as rs
 +
 +def RunCommand():​
 +  go = GetObject()
 +  go.SetCommandPrompt("​Select annotation"​)
 +  go.GeometryFilter = ObjectType.Annotation
 +  go.Get()
 +  if go.CommandResult() <> Result.Success:​
 +    return Result.Failure
 +  annotation = go.Object(0).Object()
 +  if annotation == None or not isinstance(annotation,​ AnnotationObjectBase):​
 +    return Result.Failure
 +
 +  print "​Annotation text = {0}"​.format(annotation.DisplayText)
 +
 +  return Result.Success
 +
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/gettext.txt ยท Last modified: 2015/09/14 (external edit)