Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:addtext [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Add Text =====
 +
 +===== C# =====
 +<code c#>
 +public static Rhino.Commands.Result AddAnnotationText(Rhino.RhinoDoc doc)
 +{
 +  Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(10,​ 0, 0);
 +  const string text = "Hello RhinoCommon";​
 +  const double height = 2.0;
 +  const string font = "​Arial";​
 +  Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();​
 +  plane.Origin = pt;
 +  Guid id = doc.Objects.AddText(text,​ plane, height, font, false, false);
 +  if( id != Guid.Empty )
 +  {
 +    doc.Views.Redraw();​
 +    return Rhino.Commands.Result.Success;​
 +  }
 +  return Rhino.Commands.Result.Failure;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Shared Function AddAnnotationText(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
 +  Dim pt As New Rhino.Geometry.Point3d(10,​ 0, 0)
 +  Const text As String = "Hello RhinoCommon"​
 +  Const height As Double = 2.0
 +  Const font As String = "​Arial"​
 +  Dim plane As Rhino.Geometry.Plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
 +  plane.Origin = pt
 +  Dim id As Guid = doc.Objects.AddText(text,​ plane, height, font, False, False)
 +  If id <> Guid.Empty Then
 +    doc.Views.Redraw()
 +    Return Rhino.Commands.Result.Success
 +  End If
 +  Return Rhino.Commands.Result.Failure
 +End Function
 +</​code>​
 +===== Python =====
 +<code python>
 +import Rhino
 +import scriptcontext
 +import System.Guid
 +
 +def AddAnnotationText():​
 +    pt = Rhino.Geometry.Point3d(10,​ 0, 0)
 +    text = "Hello RhinoCommon"​
 +    height = 2.0
 +    font = "​Arial"​
 +    plane = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
 +    plane.Origin = pt
 +    id = scriptcontext.doc.Objects.AddText(text,​ plane, height, font, False, False)
 +    if id!=System.Guid.Empty:​
 +        scriptcontext.doc.Views.Redraw()
 +        return Rhino.Commands.Result.Success
 +    return Rhino.Commands.Result.Failure
 +
 +
 +if __name__=="​__main__":​
 +    AddAnnotationText()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/addtext.txt ยท Last modified: 2015/09/14 (external edit)