ObjectTable.Add - bug when adding TextEntity

rhinocommon
bug

#1

ObjectTable.Add Method (GeometryBase geom, ObjectAttributes attr)
http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_Tables_ObjectTable_Add_1.htm

for Geometry Type TextEntity the Attr will not be taken care of

        ObjectAttributes attr = new ObjectAttributes();
        attr.ColorSource = ObjectColorSource.ColorFromObject;
        attr.ObjectColor = Color.FromArgb(0, 200, 0); // some green
        attr.SetUserString("myKey", "someFancyValue");

        Plane pl = Plane.WorldXY;
        double txt_height = 20;
        TextEntity txt = new TextEntity
              {
                Plane = pl,
                Text = "Hello Attributes",
                Justification = TextJustification.MiddleCenter,
                FontIndex = doc.Fonts.FindOrCreate("Arial", false, false),
                TextHeight = txt_height 
              };
        // Add ---> attr with no effect
        if (doc.Objects.Add(txt, attr) == Guid.Empty)
            return Result.Failure;

        Transform xForm = Transform.Translation(0,txt_height * 1.2,0);
        pl.Transform(xForm);
        txt.Plane = pl;
       // AddText --> attr as expected
        if (doc.Objects.AddText(txt,attr) == Guid.Empty)
            return Result.Failure;

Adding a TextEntity with Add - Attributes will not be used.
Adding a TextEntity with AddText - Attributes will affect the Object
.
.
.
work arround

    protected Guid AddToRhinoDoc(RhinoDoc doc, GeometryBase geo, ObjectAttributes attr)
    {
        Guid id = Guid.Empty;
        TextEntity txt = geo as TextEntity;
        if (null != txt)
        {
            id = doc.Objects.AddText(txt, attr);
        }
        else
        {
            id = doc.Objects.Add(geo, attr);
        }
    }

(Dale Fugier) #2

Hi Tom,

I am not able to repeat what you are reporting with the most up-to-date Rhino 5 for Windows and the following test command:

https://github.com/dalefugier/SampleCsCommands/blob/master/SampleCsText.cs

What am I missing?

– Dale


#3

change line 67
…var object_id = doc.Objects.AddText(text, attr);
to
…var object_id = doc.Objects.Add(text, attr);
your attr should not take affect
???
coding and listing to:


(Dale Fugier) #4

This should be fixed in the Rhino WIP.

http://mcneel.myjetbrains.com/youtrack/issue/RH-29769

Let me know if you find otherwise…

– Dale