Skip to content

Instantly share code, notes, and snippets.

@tmakin
Last active July 29, 2020 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmakin/8191c31053db652c2d4a2cec1fd4ee84 to your computer and use it in GitHub Desktop.
Save tmakin/8191c31053db652c2d4a2cec1fd4ee84 to your computer and use it in GitHub Desktop.
Rhino Text Generation Bug
/// <summary>
/// Repro for intermittent failure of TextEntity.CreateExtrusions
/// The issue also affects TextEntity.CreateSurfaces
///
/// Expected Output:
/// - "ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789" rendered on every line
///
/// Actual Output:
/// - About 50% of the lines are truncated abd only print part of the string because the generated extrusion is null.
/// e.g. "ABCDEFGHIJ"
///
/// Rhino Version 6 SR27 (6.27.20176.5001, 24/06/2020)
/// </summary>
public static void RhinoTextBugReport()
{
for (var row = 0; row < 20; row++)
{
// text size
var textHeight = 1;
// font
var font = Font.InstalledFonts().FirstOrDefault(o => o.EnglishFamilyName == "Arial" && o.Bold);
var plane = Rhino.Geometry.Plane.WorldXY;
plane.OriginY = 2 * row * textHeight;
// text entity
var entity = new TextEntity()
{
PlainText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789",
Plane = plane
};
// dimension style for rendering
var dimStyle = new DimensionStyle
{
Font = font,
TextHorizontalAlignment = TextHorizontalAlignment.Left,
TextVerticalAlignment = TextVerticalAlignment.Middle,
TextHeight = textHeight
};
// this is the call that fails
var extrusions = entity.CreateExtrusions(dimStyle, 2);
// add to doc
var doc = Rhino.RhinoDoc.ActiveDoc;
foreach (var item in extrusions)
{
// sometimes the extrusions in the array are null, but not always
if(item != null)
{
doc.Objects.AddExtrusion(item);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment