Click or drag to resize

DisplayPipelineDraw2dText Method (String, Color, Point2d, Boolean)

Draws 2D text on the viewport.

Namespace:  Rhino.Display
Assembly:  RhinoCommon (in RhinoCommon.dll)
Since: 5.0
Syntax
public void Draw2dText(
	string text,
	Color color,
	Point2d screenCoordinate,
	bool middleJustified
)

Parameters

text
Type: SystemString
the string to draw.
color
Type: System.DrawingColor
text color.
screenCoordinate
Type: Rhino.GeometryPoint2d
definition point in screen coordinates (0,0 is top-left corner)
middleJustified
Type: SystemBoolean
if true text is centered around the definition point, otherwise it is lower-left justified.
Examples
using Rhino;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Commands;
using Rhino.Input.Custom;

namespace examples_cs
{
  public class DrawStringCommand : Command
  {
    public override string EnglishName { get { return "csDrawString"; } }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var gp = new GetDrawStringPoint();
      gp.SetCommandPrompt("Point");
      gp.Get();
      return gp.CommandResult();
    }
  }

  public class GetDrawStringPoint : GetPoint
  {
    protected override void OnDynamicDraw(GetPointDrawEventArgs e)
    {
      base.OnDynamicDraw(e);
      var xform = e.Viewport.GetTransform(CoordinateSystem.World, CoordinateSystem.Screen);
      var current_point = e.CurrentPoint;
      current_point.Transform(xform);
      var screen_point = new Point2d(current_point.X, current_point.Y);
      var msg = string.Format("screen {0:F}, {1:F}", current_point.X, current_point.Y);
      e.Display.Draw2dText(msg, System.Drawing.Color.Blue, screen_point, false);
    }
  }
}
Python
from Rhino import *
from Rhino.DocObjects import *
from Rhino.Geometry import *
from Rhino.Commands import *
from Rhino.Input.Custom import *
from System.Drawing import Color

def RunCommand():
  gp = GetDrawStringPoint()
  gp.SetCommandPrompt("Point")
  gp.Get()
  return gp.CommandResult()

class GetDrawStringPoint(GetPoint):
  def OnDynamicDraw(self, e):
    xform = e.Viewport.GetTransform(
      CoordinateSystem.World, CoordinateSystem.Screen)    

    current_point = e.CurrentPoint
    current_point.Transform(xform)
    screen_point = Point2d(current_point.X, current_point.Y)

    msg = "screen {0}, {1}".format(screen_point.X, screen_point.Y)
    e.Display.Draw2dText(msg, Color.Blue, screen_point, False)

if __name__ == "__main__":
  RunCommand()
See Also