Custom conduit overlay text

Hi all!

I am using a custom display conduit to overlay some on-screen text, or HUD, as user feedback (for some python scripts I’m developing) overriding the DrawOverlay() function in the custom display conduit.

For purposes of legibility, it would be great to either:

  1. Mask the text.
  2. Create a semi transparent background for the whole HUD

The purpose is to still be able to read the text when there are objects below it when the user pans / zooms / etc.

Any ideas as to how this may be achieved?

Yes, this is possible. I don’t have a python sample to show you. But perhaps you can gleam something from this C++ example.

Thanks Dale.

I see that the key is the .NET method DrawString using a brush (which, if i understood correctly is the actual mask).

More useful, perhaps, is the MeasureString (the equivalent of which does not exist in python / rhinopython / rhinoscriptsyntax) method which returns the string’s height and width in pixels.

Now, the problem in translating it to python:
Once I have the pixel height and width of a given string, how do I then draw a rectangle in the custom display conduit’s DrawOverlay function at the correct screen coordinates and pixel size without too much messing around with converting from world to screen units??

I was also going to ask a similar question, so I post it here.
I would like to draw the framerate in the Holomark view.
I know you answered this back on the old NG, but I can’t find the script example you made.

Could you point me in the right direction?

Rhino.Display.DisplayPipeline.Measure2dText is what you need.

nowhere to be found???

Ah! it’s to be implemented in SR10. Got it!

On the same topic, it would be really great to be able to draw MASKED text in both the Draw3dText and Draw2dText functions in the DisplayPipeline.

It would be very useful in displaying overlay data for example, without having to rely on Text Dots for the mask.

Hi again Dale,

Updated to the latest build and voila’ there’s Measure2dText method :slight_smile: Great!

I’ve implemented it to mask overlay text drawn in a custom display conduit. However, I’ve noticed that the resulting rectangle is only centered horizontally around the text string whereas, vertically, the rectangle and text string are bottom aligned resulting in a greater ‘padding’ along the top of the text string (see attached image).

I am using the same worldCoordinate parameter for both Draw2dText and Measure2dText.

Any ideas as to why this would be?

I know it will center the rectangle if both Draw2DText and Measure2dText are set to be middle justified. But If I have a list of strings which should all be left justified, then I have to tweak the position of the rectangle before passing it to Draw2dRectangle?

Hi @Dale,


is not found in the RhinoCommon docs. Can you please add it ?


I’m sure next time the help is auto-generated the comments will appear. For now, here are the xml comments.

    /// <summary>
    /// Determines screen rectangle that would be drawn to using the Draw2dText(..) function
    /// with the same parameters.
    /// </summary>
    /// <param name="text">text to measure.</param>
    /// <param name="definitionPoint">either lower-left or middle of text.</param>
    /// <param name="middleJustified">true=middle justified. false=lower-left justified.</param>
    /// <param name="rotationRadians">text rotation in radians</param>
    /// <param name="height">height in pixels (good default is 12)</param>
    /// <param name="fontFace">font name (good default is "Arial")</param>
    /// <returns>rectangle in the viewport's screen coordinates on success.</returns>
1 Like