Rhino 7: Unable to add TextEntities read with File3dm

Please find attached a 3dm file that contains various TextEntity objects. These are read and added with the code below, but Rhino 7 fails to do this and only adds the curve geometries, whereas Rhino 6 has no problem and adds all.

What can I do to make these text entities behave? They are valid objects according to the IsValid property.

@dale is this something you can help with?

shipplan_titleblock.3dm (347.4 KB)

public Result RunCommand(RhinoDoc doc, RunMode mode) 
{

  string path = @"path\to\shipplan_titleblock.3dm"; // change this to where you saved the file

  using (var file3dm = File3dm.Read(path))
  {
    foreach(var o in file3dm.Objects)
    {
      if (!o.Attributes.Visible) continue;
      if (!file3dm.Layers[o.Attributes.LayerIndex].IsVisible) continue;

      GeometryBase privateCopy = o.Geometry;
      privateCopy.EnsurePrivateCopy();

      if (privateCopy is TextEntity text)
      {
        var id = doc.Objects.AddText(text);
        if (id == Guid.Empty) RhinoApp.WriteLine("Failed to add text entity with text "+text.Text);
      }
      else
      {
        doc.Objects.Add(privateCopy);
      }
    }
  }

  return Result.Success;
}

Hi @menno,

See this YT: - https://mcneel.myjetbrains.com/youtrack/issue/RH-61123

Basically, the dimension style referenced by your text entities is not in the document. Thus the failure.

– Dale

Is there something I can do in code to assign a dimension style that is in the document?

Hi @menno,

You could do something like this:

if (privateCopy is TextEntity text)
{
  text.DimensionStyleId = doc.DimStyles.Current.Id;
  var id = doc.Objects.AddText(text);

But it might be better to read the dimensions styles from the 3dm and add them to the document too.

And, you can always script the Import command. :wink:

– Dale

Scripting the Import command works. You have to make sure that the “Model Space Scale” is set to one though, this can be done in code:

        var dimStyle = doc.DimStyles.FindName("Default");
        if (null != dimStyle)
        {
          dimStyle.DimensionScaleValue = ScaleValue.OneToOne(); 
          doc.DimStyles.Modify(dimStyle, dimStyle.Id, true);
        }
1 Like